☕ Java Beginner

What is a wrapper class in Java?

Why Interviewers Ask This

This is a classic screening question for Java roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Wrapper classes are object representations of Java's eight primitive types: Byte, Short, Integer, Long, Float, Double, Character, and Boolean. They are needed because generics and collections like List, Map, and Set cannot work with primitives — they require objects. Wrapper classes also provide utility methods (e.g., Integer.parseInt(), Double.isNaN()) and constants (e.g., Integer.MAX_VALUE). Java 5 introduced autoboxing and unboxing to automatically convert between primitives and their wrapper classes, making the distinction mostly transparent in day-to-day code.

Pro Tip

This topic has Java-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.