Memra

Primitive types & literals

◈ 4 cards

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:

TypeSizeHoldsExample
booleantrue/falsetrue
byte8-bitsmall int42
short16-bitint1000
int32-bitint (default)100000
long64-bitbig int9_000_000_000L
float32-bitdecimal3.14f
double64-bitdecimal (default)3.14
char16-bitone 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.

NORMAL ~/memra/learn/java-from-zero/primitives-and-literals utf-8 LF