Wrapper classes in JAVA
Wrapper class is a feature in java that enables a data type to be converted in to an object of a class.This gives the programmer to use a lot of functionalities available in these wrapper classes and make java actually an object oriented programming language. Wrapper class is also helpful to have fu
Wrapper class is a feature in java that enables a data type to be converted in to an object of a class.This gives the programmer to use a lot of functionalities available in these wrapper classes and make java actually an object oriented programming language.
Wrapper class is also helpful to have functionality like conversion from one type to another. For example a numeric string value to an integer.
There are eight wrapper classes in java.
Here is the list of wrapper classes along with their corresponding data type.
<tbody>
Primitive Data type
Wrapper class.
int
Integer
float
Float
double
Double
long
Long
short
Short
byte
Byte
boolean
Boolean
char
Character
</tbody>
The wrapper classes are defined in the java.lang package.
The following program demonstrate how to declare objects belonging to various wrapper classes.
class WrapperClass
{
public static void main ()
{
byte vByte=50;
Short vShort=4000;
Integer vIntegar=58058;
Long vLong= 12345L;
Float vFloat=12.34F;
Double vDouble=22.5656;
Boolean vBoolean=true;
Character vCharacter='F';
System.out.println(" vByte"+ vByte);
System.out.println(" vShort"+ vShort);
System.out.println(" vInteger"+ vIntegar);
System.out.println(" vLong"+ vLong);
System.out.println(" vFloat"+ vFloat);
System.out.println(" vDouble"+ vDouble);
System.out.println(" vBoolean"+ vBoolean);
System.out.println(" vCharacter"+ vCharacter);
}
}Auto boxing:-
It is the automatic conversion of the primitive types into their corresponding object wrapper classes.
For example
Integer vintegar=24;
Public class Autoboxing
=myint;
System.out.println("Data type int: "+ myint);
System.out.println("Wrapper class integer value: "+ myinteger);
}
}Output:-
Data type int: 24
Wrapper class integer value: 24
Auto-unboxing:-
It is the reverse process of Autoboxing.
It is the conversion of Wrapper class object into its corresponding primitive type.
For example
public class Autoboxing
{
public static void main ()
{
Integer myInteger=24;
int myInt=myInteger;
System.out.println("Wrapper class integer value: "+ myInteger);
System.out.println("Data type int: "+ myInt);
}
}Output:-
Wrapper class integer value: 24
Data type int: 24
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.