Day10 : Wrapper Class

 Wrapper Class

In java corresponding to 8 primitive datatype their is a set of 8 special classes. These classes have their names resembling with the names of the datatype and the database and collectively all 8 of them are called as wrapper classes. All these wrapper class are available in the package "java.lang" and following are their names.
  1. Integer
  2. Byte
  3. Short
  4. Long
  5. Float
  6. Double
  7. Character
  8. Boolean

What is the use of wrapper class in java?

Wrapper classes are use by programmer for two purposes :
(1) We use them for converting string representation of the value to its original primitive form. For Example : To convert "25" to 25. We use the parseInt() belonging to wrapper class integer as shown below:

int a;
a = Integer.parseInt("25");
Likewise we've other parseXXX() method belonging to their respective wrapper classes.


(2) Programmer also use wrapper class for converting a variable of primitive datatype into corresponding object.
For Example : 
        int a = 10;
  The above statement is declaring a as a variable and if required then we can convert the variable a into integer object and is done by using the Wrapper class integer as shown below:
Integer obj = a;
This is needed in the topic collection.


Comments

Popular posts from this blog

Day2 : Compiling Java Program with Examples

Day1: Introduction to Java and its feature

What does System.out.printf( "%-15s%03d\n", s1, x) do?