In Java there are eight primitive datatypes and they
are as below and they are called as Wrapper classes. The wrapper classes are part of the java.lang package, which
is imported by default into all Java programs.
Primitive
|
Wrapper Class
|
boolean
|
Boolean
|
byte
|
Byte
|
char
|
Character
|
int
|
Integer
|
float
|
Float
|
double
|
Double
|
long
|
Long
|
short
|
Short
|
Importance of Wrapper classes
There are mainly two uses with wrapper classes.- To convert simple data types into objects, that is, to give object form to a data type; here constructors are used.
- To convert strings into data types (known as parsing operations), here methods of type parsexxx() are used.
Following is the hierarchy of the above classes.
Difference between a primitive data type and an object of a wrapper class:
int a = 10; // declares an int variable named a and initializes it with the value 10
Integer b= new Integer(20); // The object is initialized with the value 20 and a reference to the object is assigned to the object variable b.
In simple way this is wrapper class.
No comments :
Post a Comment