PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Wrapper Class in Java

← All stacks

Theory

62/270

Wrapper Class in Java

Wrapper classes box primitives into objects: int → Integer, double → Double, boolean → Boolean. ArrayList and HashMap need objects, not raw int.

Autoboxing — Integer n = 5; Unboxing: int x = n;. If n is null, unboxing throws NullPointerException — a favourite trap.

Use wrappers in collections. Use primitives for simple maths — cheaper.

Let's take this on the board with one tiny Main class — no extra files. Wrapper Class in Java — 10 is boxed into Integer, then unboxed back to int for math. Start from main, go line by line, and stop at each print. That output is the proof for Wrapper Class.

Exam tip

Why wrappers? Lists need objects. Then mention null unboxing NPE.

Example

// Wrapper / autoboxing
public class Main {
  public static void main(String[] args) {
    Integer a = 10; // autobox
    int b = a;       // unbox
    System.out.println(a + b);
  }
}

Wrapper Class in Java — 10 is boxed into Integer, then unboxed back to int for math.

Short notes

  • DefWrapper = object version of a primitive (int → Integer).
  • RuleCollections store Integer, not int.
  • RememberAutoboxing int → Integer. Unboxing Integer → int.
  • TrapUnboxing null Integer → NullPointerException.

Questions

1

What is Integer?

2

Why wrappers?

3

Null Integer unboxed?

Previous← Java Math Class (Methods with Examples)NextRecursion in Java →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.