Primitive Type vs Reference Type

Primitive Type vs Reference Type

8 Primitive Data Type
https://en.wikibooks.org/wiki/Java_Programming/Primitive_Types

boolean A binary value of either true or false
byte 8 bit signed value, values from -128 to 127
short 16 bit signed value, values from -32.768 to 32.767
char 16 bit Unicode character
int 32 bit signed value, values from -2.147.483.648 to 2.147.483.647
long 64 bit signed value, values from -9.223.372.036.854.775.808 to 9.223.372.036.854.775.808
float 32 bit floating point value
double 64 bit floating point value

Object Types

Data type Description
Boolean A binary value of either true or false
Byte 8 bit signed value, values from -128 to 127
Short 16 bit signed value, values from -32.768 to 32.767
Character 16 bit Unicode character
Integer 32 bit signed value, values from -2.147.483.648 to 2.147.483.647
Long 64 bit signed value, values from -9.223.372.036.854.775.808 to 9.223.372.036.854.775.808
Float 32 bit floating point value
Double 64 bit floating point value
String N byte Unicode string of textual data. Immutable

Reference Types

class A class is also a data type – a non primitive reference data type
interface An interface is a reference type in Java, it is similar to class, it is a collection of abstract methods.
array An array’s type is written as type[] , where type is the data type of the contained elements; arrays are objects, are dynamically created, and may be assigned to variables of type Object
enum An enum type is a special data type that enables for a variable to be a set of predefined constants.

 

Naming Convention

http://www.oracle.com/technetwork/java/codeconventions-135099.html

Identifier Type

Rules for Naming

Examples


Packages

The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.Subsequent components of the package name vary according to an organization’s own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.
com.sun.engcom.apple.quicktime.v2

edu.cmu.cs.bovik.cheese


Classes

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

class Raster;
class ImageSprite;

Interfaces

Interface names should be capitalized like class names.

interface RasterDelegate;
interface Storing;

Methods

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.

run();
runFast();
getBackground();

Variables

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary “throwaway” variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
int             i;
char            c;
float           myWidth;

Constants

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores (“_”). (ANSI constants should be avoided, for ease of debugging.)

static final int MIN_WIDTH = 4;static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;

 

Command-Line Arguments (C vs Java)


/* command line arguments in C */
void main(int argc, char** argv)
{
    char name[128]; 
    int age = 0; 
    if (argc >= 2) { 
        strcpy(name, argv[1]); 
        age = atoi(argv[2]); 
        printf("%s, name = %s, age = %d\n", argv[0], name, age); 
    } 
}

~>person.exe Park 20

argv[0] = “person.exe”

argv[1] = “Park”

argv[2] = “20”

 


// command line arguments in Java
public class Person {
    public static void main(String[] args) {
        String name = ""; 
        int age = 0; 
        if (args.length >= 2) { 
            name = args[0]; 
            age = Integer.parseInt(args[1]); 
            System.out.printf("name = %s, age = %d\n", name, age); 
        } 
    }
}

~>java Person Park 30

args[0] = “Park”

args[1] = “30”

 

Homework Grading Policy

숙제 Grading 기준

컴파일 에러 0
보고서, 소스코드, 프로젝트 파일 폴더 전체가 없음 0
소스코드에 주석없을 시 -5 (소스코드 첫부분에 Lab번호, 본인이름, 학번, 날짜적을 것)
코드 실행 에러 및 잘못된 결과 -1
Your Code 없음 -1

보고서파일포멧 (hwp/doc(x)/pdf 아닐시) 0
보고서 제출안함 -3 (보고서표지에 Lab번호, 분반번호, 제출일, 학번, 이름을 적을것)
보고서에 내용을 작성하지 않고 소스코드 사진캡쳐해서 붙여넣기 -3
보고서에 소스코드 내용을 작성하지 않고 다른 것 적기 -3
보고서에 Your Code 설명 없음 -1
보고서에 실행결과창 없음 -1