Wrapper Class in Java

Wrapper Class in Java

1. As we know Java is not pure Object Oriented Language just because of it uses Primitive Data Type. So Java provide Wrapper class to make these primitive type to pure Object type.

2. Wrapper classes are some predefine classes to wrap primitive data type as an Object type.

3. Wrapper class can hold only its respective primitive data type.

4. Wrapper class uses in Collection Frameworks , Hibernate Frameworks and Spring Frameworks etc.

5. There are following types of Wrapper Classes:

Primitive Type Wrapper Type
byte Byte
short Short
char Character
int Integer
long Long
float Float
double Double
boolean Boolean

What is Autoboxing and Unboxing

In Java 5 there is new feature introduce that is called Autoboxing and Unboxing.

Autoboxing

When you wrap primitive data type to its respective Wrapper class that process is called Autoboxing.

Example

        int i=10;
        Integer j=i;
    

Unboxing

When you wrap wrapper to its respective primitive data type that process is called Unboxing.

Example

        Integer i=10;
        int j=i;
    

2 comments:

Vinit Pal said...

Thanks for all your code and new technology

RohitMachiwal said...

thank you so much for this sir