Wrapper classes in Java

We all many know that Java is Object Oriented programming and in the world of Java everything will be considered as an Object. In that case when we see about primitive datatypes in java those are all not under any classes in Java. And also before JDK 1.5 all data structures used to store only Objects. In those cases they have came with Wrapper classes for all 8 primitive datatypes in Java. As a name represents "Wrapper" it wraps around the primitive datatype and gives the Objects. How these wrapping are done in Java from primitive to Wrapper class objects?Wrapping done by using constructor of each classes. Each class will accept different types of primitive datatype or Object as a constructor parameter and those parameters are converted to Objects. All these 8 Wrapper classes comes inside java.lang package and immutable classes. Apart from these 8 Wrapper classes other wrapper classes like BigDecimal and BigInteger are not one of the primitive wrapper classes and are mutable. Below are the list of 8 primitive datatypes and their corresponding Wrapper classes along with their constructor parameter types.

Primitive type

Wrapper class

Constructor Arguments

byte

Byte

byte or String

short

Short

short or String

int

Integer

int or String

long

Long

long or String

float

Float

float, double or String

double

Double

double or String

char

Character

char

boolean

Boolean

boolean or String

Bellow is the Wrapper class hierarchy

The Byte, Short, Integer, Long, Float, and Double wrapper classes are all sub-classes of the Number class. Lets see small example for converting primitive datatype to Object and from Object to primitive type.