What are Wrapper Classes in Java

Java » What are Wrapper Classes in Java

Java supports a number of primitive data types or built-in types such as int, float, bool etc. variable which is followed by one of these primitive types can only store that corresponding value type. In other words, if a variable is of float type, then it keeps float values only . Therefore, there is no sense of having methods.

Java provides a way to make a datatype to act as an object and this object keeps only these particular corresponding type of values, allowing these object to have useful methods to work with.


The concept of representing a primitive type as an object and the object that belongs to a class is known as Wrapper class. For example, Integer, Float, Boolean are Wrapper classes. Wrapper classes are subclasses of abstract Number class.

 

There are some conversion operations among these wrapper classes and primitive type :
1) Boxing: When a primitive type is converted to its corresponding wrapper class’s object explicitly, is known as Boxing.

 

2) Unboxing: When an object of the wrapper class is converted to primitive type explicitly, is known as Unboxing.

 

3) Autoboxing: When a primitive type is converted to its corresponding wrapper class’s object, implicitly by the compiler is known as Autoboxing.

4) Autounboxing: When an object of the wrapper class is converted to primitive type, implicitly by the compiler is known as Autounboxing.

Related program:

Java program to demonstrate the working Integer Wrapper Class


You must be logged in to take the quiz.

error: Content is protected !!