Primitive types (기본형)

  • The variable contains the value itself
  • what are they
    • byte
    • short
    • int
    • long
    • float
    • double
    • char
    • boolean
// 변수 선언 variable declaration
int a; // type variableName;
  • camelCase recommended
// primitive types
int myInt = 123;
long myLong = 12343245325L; // add L (or l)
float myFloat = 3.14f; // add f
double myDouble = 3.143252;
boolean myBoolean = true;
 
char a1 = 'a';
char a2 = 97;
 
// class
String myString = "hello";
  • String is actually a class
    • the myString variable is now the String class’s instance

Reference type (참조형)

  • The variable points to where the value is stored
  • null can only be stored in reference types!
    • the default value of a reference type is null
  • types
    • objects
    • String
    • int[]
Person p1, p2;
p1 = new Person("Leejun", 23);
p2 = p1;
p2.setName("Kirby") // p1 name's will change too!
  • p1 and p2 points to the same person instance