Skip to content
UniCircle
EasyConceptualData types

Primitive types vs reference types

Question JAVA-BAS-004

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.

PrimitiveReference
Holdsthe valuea reference to an object
Can be nullnoyes
Field default0, 0.0, false, '\u0000'null
Compared with ==by valueby identity (same object?)
Methodsnoneyes
Java
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 array

Java 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.