Every value in a Java program has a type, and the compiler enforces those types before a single line runs. That strictness is Java's biggest gift to beginners: entire categories of bugs get caught at compile time instead of exploding in production. But it also means you cannot write serious Java until the type system is second nature.
This guide covers both families — primitives and reference types — plus the casting rules and overflow behavior that interviewers use to separate memorizers from people who actually understand the machine.
The two families: primitive vs reference
Java splits all types into two camps:
- Primitive types store the value itself, directly in the variable. There are exactly 8, they are built into the language, and their names are lowercase:
int,double,booleanand friends. - Reference types store a reference (an address) to an object living on the heap.
String, arrays,ArrayList, and every class you write are reference types.
The practical differences show up everywhere:
| Aspect | Primitive | Reference |
|---|---|---|
| Stores | The actual value | Address of an object |
| Can be null | Never | Yes |
| Default (as a field) | 0 / 0.0 / false / ' |

