Java: Primitive Types
byte |
|
---|---|
Description | 8-bit signed integer |
Range | |
Format | Two’s complement |
Default Value | 0 |
Boxed Type |
java.lang.Byte
|
Example Literals | |
short |
|
Description | 16-bit signed integer |
Range | |
Format | Two’s complement |
Default Value | 0 |
Boxed Type |
java.lang.Short
|
Example Literals | |
int |
|
Description | 32-bit signed integer |
Range | |
Format | Two’s complement |
Default Value | 0 |
Boxed Type |
java.lang.Integer
|
Example Literals |
0 1 2147483648
Binary:
0b1001 0b1111
Octal:
010 0777 0111
Hex:
0x1E3C 0xFFFFFF 0xCAFEBABE
With underscores:
1_000_000 0xFFFF_FFFF
|
long |
|
Description | 64-bit signed integer |
Range | |
Format | Two’s complement |
Default Value | 0 |
Boxed Type |
java.lang.Long
|
Example Literals |
0L 123456L
Binary:
0b10101010L
Octal:
010L 0777L
Hex:
0x1E3CL 0xFFFFFFL 0xCAFEBABEL
With underscores:
1_000_000L 0xFFFF_FFFFL
|
float |
|
Description | 32-bit real |
Range | |
Precision | ~6 digits |
Format | IEEE 754 |
Default Value | 0 |
Boxed Type |
java.lang.Float
|
Special Values |
The smallest value greater than zero
|
Example Literals |
1.0f 3.1415f .5f
1e5f 1.1e-20f 1.1e+003f
Hex:
0x1.8p2f 0x1.FFFFFEp+127f
|
double |
|
Description | 64-bit real |
Range | |
Precision | ~15 digits |
Format | IEEE 754 |
Default Value | 0 |
Boxed Type |
java.lang.Double
|
Special Values |
The smallest value greater than zero
|
Example Literals |
1.0 3.1415 .5
1e5 1.1e-20 1.1e+003
Hex:
0x1.8p2 0x1.FFFFFFFFFFFFFp+1023
With suffix:
1.0d 1.1e-20d
|
char |
|
Description | Unicode character (or 16-bit unsigned integer) |
Range | |
Format | UTF-16 |
Default Value | \u0000 (0) |
Boxed Type |
java.lang.Character
|
Example Literals |
'a' '\n' '"' '\\' '\'' 'π' 'д'
|
boolean |
|
Description | True or false |
Format | undefined |
Default Value | false |
Boxed Type |
java.lang.Boolean
|
Special Values |
Boxed true
Boxed false
|
Example Literals |
true false
|
Comments
Be the first to comment!