Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Wrapper Classes

Lesson 28 of 39 in the free Java notes on Siksha Sarovar, written by Rohit Jangra.

Wrapper Classes

In Java, every primitive data type has a corresponding class which works like a wrapper. It provides a mechanism to wrap primitive data into an object. • All wrapper classes are final and present in java.lang package.

Mapping:

PrimitiveWrapper Class
booleanBoolean
charCharacter
intInteger
doubleDouble

(Byte, Short, Integer, Long, Float, Double are subclasses of Number class).

Use of Wrapper Class

  1. To represent primitive data as Objects (Reference Types).
  2. To convert String primitives to actual primitives (Parsing).
  3. Used in Collections which store only Objects.

AutoBoxing & Unboxing

  1. AutoBoxing:
  2. Automatic conversion of primitive type into its corresponding wrapper object. Integer i = 10; // AutoBoxed

  3. Unboxing:
  4. Automatic conversion of wrapper object into its corresponding primitive type. int j = i; // Unboxed

Parsing (String to Primitive)

Every wrapper class has a valid static method parseXxx(String s). • public static int parseInt(String s)public static double parseDouble(String s)public static boolean parseBoolean(String s)Note: char cannot be parsed (Use charAt()).

NumberFormatException

Thrown when trying to convert a String with invalid format into a number. Example: Integer.parseInt("123a") throws NumberFormatException.