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.

Primitive Data type Wrapper class.
int Integer
float Float
double Double
long Long
short Short
byte Byte
boolean Boolean
char Character

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here