Java

Wrapper Classes

Primitives as Objects! Understand Autoboxing and Unboxing in Java.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Primitives as Objects! Understand Autoboxing and Unboxing in Java. This hands-on tutorial focuses on practical implementation of wrapper classes concepts.

Wrapper Classes

Wrapper classes provide a way to use primitive data types (int, boolean, etc.) as objects.

Sometimes you must use wrapper classes, for example when working with Collection objects like ArrayList, where primitive types cannot be used.

Primitive vs Wrapper

PrimitiveWrapper Class
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
booleanBoolean
charCharacter

Creating Wrapper Objects

Integer myInt = 5;
Double myDouble = 5.99;
Character myChar = 'A';

Autoboxing & Unboxing

  • Autoboxing: Automatic conversion of primitive type to its corresponding object wrapper class.

    Character ch = 'a'; // Autoboxing
    
  • Unboxing: Automatic conversion of wrapper class to primitive type.

    char c = ch; // Unboxing
    

Interactive Code

See how wrappers work.

JAVA PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "Java Wrapper Classes, Autoboxing and Unboxing"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 3

Which is the wrapper class for `int`?

Int
Integer
Number
BigInt

Next Steps

Programs don't always run smoothly. What happens when things go wrong? Module 7: Exception Handling.