What is the difference between primitive and reference types in Java? Mention memory, default values and null.
Show the explanation
Java has 8 primitives: byte, short, int, long, float, double, char, boolean. A primitive variable holds the value itself. Every other type (classes, interfaces, arrays, enums, records) is a reference type: the variable holds a reference to an object on the heap.
| Primitive | Reference | |
|---|---|---|
| Holds | the value | a reference to an object |
Can be null | no | yes |
| Field default | 0, 0.0, false, '\u0000' | null |
Compared with == | by value | by identity (same object?) |
| Methods | none | yes |
int a = 5; int b = a; b++; // a is still 5: the value was copied
int[] x = {5}; int[] y = x; y[0]++; // x[0] is now 6: both refer to one arrayJava is always pass-by-value: for references, the reference is copied, so a method can change the object but cannot make the caller's variable point somewhere else. Wrapper classes (Integer, Double, …) bridge the two worlds via autoboxing.
Original UniCircle question. Last reviewed 22 Oct 2026.
