기본 형식
type variableName;
int intVariable;
String stringVariable;
char[] charArray;
변수 이름 규칙
- 대소문자 구분
- 숫자 시작 X
_ , $ 사용 가능 → but $는 자동 생성되는 변수명, _는 상수에 쓰이므로 사용 권장 안함
- Camel Case
변수 타입
| byte | 8bits | -2^7 ~ 2^7-1 (-128 ~ 127) |
| short | 16bits | -2^15 ~ 2^15-1 (-32768 ~ 32767) |
| int | 32bits | -2^31 ~ 2^31-1 (-2147483648 ~ 2147483647) |
| long | 64bits | -2^63 ~ 2^63-1 (-9223372036854775808 ~ 9223372036854775807) |
| float | 32bits | *single-precision 32-bit IEEE 754 floating point |
| double | 64bits | *double-precision 64-bit IEEE 754 floating point |
| char | 16bits | \u0000 ~ \uffff (0 ~ 2^15-1) |
| boolean | Virtual Machine Depentdent | true, false |
int x = 1234;
int x = 1234567890;
long x = 1234567890L;
float f = 3.14f;
double f = 3.14;
char a1 = 'a';
char a2 = 97;
char a3 = '\u0061';
char a4 = '가';
boolean x = true;
String a = "Hello";
타입 기본 값
| byte | 0 |
| short | 0 |
| int | 0 |
| long | 0L |
| float | 0.0f |
| double | 0.0d |
| char | '\u0000' |
| boolean | false |
Literal
int x = 1234;
long x = 1234L;
long x = 12345678910L;
float g = 3.14f;
double k = 314d;