Java: Primitive Types

byte
Description 8-bit signed integer
Range
−128
 … 
127
−27
 … 
27−1
Format Two’s complement
Default Value 0
Boxed Type java.lang.Byte
Example Literals
short
Description 16-bit signed integer
Range
−32,768
 … 
32,767
−215
 … 
215−1
Format Two’s complement
Default Value 0
Boxed Type java.lang.Short
Example Literals
int
Description 32-bit signed integer
Range
−2,147,483,648
 … 
2,147,483,647
−231
 … 
231−1
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
−9,223,372,036,854,775,808
 … 
9,223,372,036,854,775,807
−263
 … 
263−1
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
± 3.40282347×1038
± 1.11111111111111111111111×2127
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
± 1.7976931348623157×10308
± 1.11111111111111111…111×21023
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
\u0000
 … 
\uFFFF
0
 … 
65,535
0
 … 
216−1
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!