0% found this document useful (0 votes)
7 views

Wrapper Classes

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Wrapper Classes

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Why Java is not a purely Object-Oriented Language?

Java is not pure object oriented programming language just because of primitive
data
types like byte, short, int, char, float, double, long, boolean etc.

Wrapper Classes: To convert primitives into object and object to primitives then we
can use wrapper classes.
Wrapper classes came into java 1.5 version.

primitive Data Type Wrapper class

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

Boxing : It is process of converting primitive dataType into wrapper object by


programmer is called as boxing.

Unboxing: It is process of converting Wrapper Object into primitive DataType by


programmer is called as Unboxing.

Example :

package wrapperClassess;

public class BoxingAndUnboxing {


public static void main(String[] args) {

int a = 10;
System.out.println("Primitive dataType = " + a);

// boxing
Integer A = Integer.valueOf(a);
System.out.println("Wrapper Object = " + A);

// unboxing
int a1 = A.intValue();
System.out.println("Private DataType = " + a1);

short s = 35;
System.out.println("primitive dataType =" + s);
// boxing
Short S = Short.valueOf(s);
System.out.println("Wrapper Object = " + S);

// unboxing
short s1 = S.shortValue();
System.out.println("primitive dataType =" + s1);
}
}

AutoBoxing: It is process of converting primitive dataType into wrapper object by


compiler is called as Autoboxing.

AutoUnboxing:It is process of converting Wrapper Object into primitive DataType by


compiler is called as AutoUnboxing.

Example :

package wrapperClassess;

public class AutoBoxingAndAutoUnboxing {

public static void main(String[] args) {

int a = 10;
System.out.println("primitive dataType = " + a);

// autoBoxing
Integer i = a;// Integer.valueOf(a);
System.out.println("Wrapper Object = " + i);

// autoUnboxing
int i1 = i;// i.intValue();
System.out.println("Primitive dataType = " + i1);

short s = 89;
System.out.println("short dataType = " + s);
// autoBoxing
Short s1 = s;// Short.valueOf(s);
System.out.println("Wrapper Object =" + s1);

Short s11 = s1; // Short.shortValue()


System.out.println("Primitive dataType" + s11);
}
}

You might also like