← Back to libraryQuestion 51 of 273
JavaBeginner

Boxing and Unboxing

📖 Detailed Explanation:

Autoboxing: Java automatically converts primitives to Wrapper objects (int -> Integer). Unboxing: Java automatically converts Wrapper objects back to primitives. This happens transparently but has performance implications and can cause NullPointerException if not careful.

🌍 Real-World Example:

Boxing: Putting a coin in a box. Unboxing: Taking the coin out. Autoboxing: The box automatically opens and closes when you approach/leave.

🎯 Scenario-Based Interview Question:

What's the performance impact of excessive boxing/unboxing? Provide an example.