Over 10 years we helping companies reach their financial and branding goals. Onum is a values-driven SEO agency dedicated.

CONTACTS
ECET 2026 CSE

Day 72 night – Java – Wrapper Classes + Autoboxing

Concept Notes (Deep Explanation + Examples)

🔹 1. Why Wrapper Classes Exist (The Basic Need)

In Java, primitive data types (int, double, char, etc.) are not objects.
But many Java features work only with objects, such as:

  • Collections (ArrayList, HashMap)
  • Generics
  • Frameworks & APIs
  • Object-based utilities

👉 To bridge this gap, Java provides Wrapper Classes.

PrimitiveWrapper Class
intInteger
doubleDouble
charCharacter
booleanBoolean
floatFloat
longLong
shortShort
byteByte

💡 Exam Point: Wrapper classes are part of java.lang package (import not required).


🔹 2. What is a Wrapper Class?

A Wrapper Class converts a primitive value into an object.

Example:

int a = 10;
Integer obj = Integer.valueOf(a);

Now obj behaves like an object and can be used in collections.

📌 Real-world analogy:
Primitive = raw data
Wrapper = data packed in a box so it can be transported anywhere


🔹 3. Autoboxing (Primitive → Object)

Autoboxing means Java automatically converts a primitive into its wrapper class.

Example:

int x = 20;
Integer y = x;   // Autoboxing

👉 No need to call valueOf() explicitly.

📌 Where it happens?

  • Adding elements to ArrayList
  • Passing primitives to methods expecting objects
ArrayList<Integer> list = new ArrayList<>();
list.add(5);   // Autoboxing happens here

💡 ECET Tip: Autoboxing introduced in Java 5


🔹 4. Unboxing (Object → Primitive)

Unboxing converts a wrapper object back to a primitive.

Example:

Integer p = 30;
int q = p;   // Unboxing

Internally:

int q = p.intValue();

📌 Important:
If wrapper object is null, unboxing causes NullPointerException


🔹 5. Wrapper Class Methods (Very Important for MCQs)

MethodUse
parseInt()Converts String → primitive
valueOf()Converts primitive/String → object
toString()Converts object → String
compareTo()Compares two objects

Example:

int a = Integer.parseInt("100");
Integer b = Integer.valueOf("200");

💡 Exam Trap:
parseInt() returns primitive
valueOf() returns object


🔹 6. Wrapper Classes & Collections (Exam Favorite)

Collections cannot store primitives.

❌ Invalid:

ArrayList<int> list;

✅ Valid:

ArrayList<Integer> list;

Autoboxing automatically converts int → Integer.


🔹 7. Performance & Memory (ECET Theory Point)

  • Primitives → Faster, less memory
  • Wrapper Objects → Slower, more memory
  • Use wrappers only when objects are required

📌 ECET Question Pattern:
Which is faster? → Primitive types


⚙️ Formulas (Plain LaTeX, No Boxes)

👉 No mathematical formulas applicable for Java Wrapper Classes & Autoboxing


🔟 10 MCQs (ECET + GATE Hybrid)

Q1. Which package contains wrapper classes?
A. java.util
B. java.io
C. java.lang
D. java.wrapper

Q2. Autoboxing was introduced in which Java version?
A. Java 1.2
B. Java 1.4
C. Java 5
D. Java 8

Q3. Which wrapper class is used for char?
A. String
B. Character
C. Char
D. Boolean

Q4. What does Integer.parseInt("50") return?
A. Integer object
B. String
C. int primitive
D. Boolean

Q5. Which collection can store integers?
A. ArrayList<int>
B. ArrayList<Integer>
C. int ArrayList
D. None

Q6. Unboxing converts:
A. Object to Object
B. Primitive to Object
C. Object to Primitive
D. String to Object

Q7. Which causes NullPointerException?
A. Autoboxing
B. Unboxing null object
C. valueOf()
D. parseInt()

Q8. Which method returns a wrapper object?
A. parseInt()
B. intValue()
C. valueOf()
D. toString()

Q9. Wrapper classes are mainly used with:
A. Loops
B. Arrays
C. Collections
D. Operators

Q10. Which is faster in execution?
A. Wrapper class
B. Objects
C. Primitive data type
D. String


Answer Key (WordPress Table — NO HTML)

Q No | Answer
1 | C
2 | C
3 | B
4 | C
5 | B
6 | C
7 | B
8 | C
9 | C
10 | C


🧠 MCQ Explanations

Q1: Wrapper classes belong to java.lang → auto imported.
Other packages do not contain wrapper classes.

Q2: Autoboxing/unboxing came in Java 5 only.

Q3: Character wraps char. Others are invalid.

Q4: parseInt() converts String → primitive int.

Q5: Collections need objects → Integer not int.

Q6: Unboxing = Object → Primitive.

Q7: Unboxing a null wrapper causes NullPointerException.

Q8: valueOf() returns wrapper object.

Q9: Wrapper classes are used mainly in Collections Framework.

Q10: Primitive types consume less memory and execute faster.


🎯 Motivation (ECET 2026 Specific)

Wrapper Classes & Autoboxing are guaranteed theory + MCQ topics in ECET CSE.
One clear question almost every year comes from this area.
Mastering this topic strengthens your Java + Collections foundation, directly boosting your rank.
👉 Small topics, big marks — revise daily!


📲 CTA (Fixed)

Join our ECET 2026 CSE WhatsApp Group for daily quizzes & study notes:
https://chat.whatsapp.com/GniYuv3CYVDKjPWEN086X9

Leave a comment

Your email address will not be published. Required fields are marked *