Reference Types & Wrapper Classes in Java
Anything that isn't one of the eight primitives is a reference type — objects, arrays, and String all qualify — and a reference-type variable holds a reference to an object living elsewhere in memory, not the object's data directly. Every primitive has a matching wrapper class — int with Integer, double with Double, boolean with Boolean, and so on — that packages that primitive value inside a real object, which matters anywhere the language requires an object instead of a raw primitive, such as a generic collection like a list of Integer, which cannot hold a raw int at all.
Autoboxing and unboxing let Java convert between a primitive and its wrapper automatically in most contexts, but it's a real conversion happening behind the scenes, not a free one. Wrapper objects can also be null, while primitives never can — unboxing a null wrapper throws a NullPointerException at runtime.
What counts as a reference type
Objects, arrays, and String — anything that isn't one of the eight primitives.
What a reference actually holds
The variable stores a reference to the object, not the object's bytes directly.
Every primitive has a wrapper class
int pairs with Integer, double with Double, char with Character, boolean with Boolean, and so on, each wrapping the primitive value inside a real object.
Autoboxing and unboxing
Java automatically converts a primitive into its wrapper (boxing) and back again (unboxing), most visibly when a primitive needs to go into a generic collection.
Wrappers can be null, primitives cannot
An uninitialized Integer field defaults to null, and unboxing a null wrapper throws a NullPointerException.
import java.util.ArrayList; public class WrapperDemo { public static void main(String[] args) { ArrayList<Integer> scores = new ArrayList<>(); scores.add(90); int first = scores.get(0); System.out.println("Stored: " + scores); System.out.println("Unboxed: " + first); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.