Primitive wrapper classes in java

To make use the fully object orient concept java introduce the derived objects of all primitive types.

Below is the list of all wrapper class in java.

Primitive data type Wrapper class
byte Byte
int Integer
double Double
long Long
boolean Boolean
char Character
float Float


Wrapper class helps you convert the primitive data type into derived variable and from derived variable to primitive data type.

All the wrapper classes are final and toString() and hashCode() method has been overridden in order to compare the state of the object.

All the wrapper classes except Character have two constructors. One constructor takes the respective data type and second constructor takes the string which convert to respective data type.

Character class has only one constructor which takes only char data type.

Auto boxing and unboxing using wrapper class

Getting the derived object from a primitive data type is called the boxing.

Getting the primitive data type from the derived object called unboxing.

Boxing and unboxing is happening automatically using wrapper classes using java 5 or newer version.

Example of wrapper classes:

public class Wrapperworld {

public static void main(String[] args) {

// Integer Example
int i = 9;
Integer intObj = new Integer(i);
int j = intObj.intValue();

// One constructor is taking the litrals
Integer intOnj2 = new Integer(10);

// One constructor is taking the String
Integer intOnj3 = new Integer("10");

// One constructor is taking the litrals
Double d1 = new Double(100.000);

// One constructor is taking the String
Double d2s = new Double("100.000");