Primitive types & literals
The eight built-in value types and how to write their literals.
Java's eight primitives
Most values in Java are either a primitive (a raw value) or a reference (a pointer to an object). There are exactly eight primitives:
| Type | Size | Holds | Example |
|---|---|---|---|
| boolean | — | true/false | true |
| byte | 8-bit | small int | 42 |
| short | 16-bit | int | 1000 |
| int | 32-bit | int (default) | 100000 |
| long | 64-bit | big int | 9_000_000_000L |
| float | 32-bit | decimal | 3.14f |
| double | 64-bit | decimal (default) | 3.14 |
| char | 16-bit | one character | 'A' |
Key literal rules: a whole number is an int unless suffixed L for long; a decimal is a double unless suffixed f for float. You can group digits with underscores for readability (1_000_000), and write other bases: 0x1F (hex), 0b1010 (binary), 0777 (octal). A char is a single character in single quotes — "A" is a String, 'A' is a char.