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

User-Defined Methods in Java for ICSE Class 10: Parameters, Return and Overloading
ICSE Class 10 Computer Applications notes on user-defined methods: method prototype and signature, formal and actual parameters, return types, call by value vs call by reference, pure and impure methods, static methods and method overloading, with programs.

ISC Practical 2027: Image Editor – Brighten an Image and Find Bright Spots (2-D Array) – Java Program
Fully solved ISC Computer Science Practical 2027 2-D array question: brighten a grayscale image (capping values at 255) and find the bright spots, pixels larger than all four neighbours. Includes a missing bright spot in CISCE’s sample output.

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.