Pages

Saturday 27 July 2013

WHAT IS WRAPPER CLASS & WAHT IS BOXING & UNBOXING&WHAT IS AUTO BOXING&AUTO UNBOXING

WHAT IS WRAPPER CLASSES:
                   In order to represent the primitive data type values with the concept of object we are going to
use some pre defined classes.
            The classes which we are using to represent primitive data values in the form of object are called as WRAPPER CLASSES.
                    to represent the each&every primitive datatype value in the form of object there will be a corresponding class is available.




        




all the wrapper classes are present inside a predefined package called as java.lang

Integer i1=new Integer(100);
Integer i2=new Integer("123");



WHAT IS BOXING:
                     the concept of representing the primitive data type value in the form of it's equivalent wrapper class object is known as boxing.
 int i=200;
Integer i1=new Integer(i);//boxing


WHAT IS UNBOXING
:
                   the concept of getting back the primitive data value which is present inside wrapper class object to corresponding primitive data type value is known as unboxing>
              int i=100;
              integer i1=new integer(i)//boxing
              int j=i1.value()//unboxing
 in order to perform unboxing we are going to use the predefined methods which are present inside wrapper classes
ex:
        class wdemo()
         {
           public static void main()
           Integer i1=new Integer(100);
           system.out.println(i);
           Integer i2=new Integer("1234");
          system.out.println(i2);
           int i=i1.intvalue();
           int j=i2.intvalue();
           int k=i+j;
           system.out.println(k);
           Integer i3=new Integer();
              system.out.println("hello");
}
}

output:
              100   
              1234   
              1334
               hello

AUTO BOXING:
                    The concept of representing the primitive data value in the form of corresponding wrapper class object automatically by the jvm is known as auto boxing.
                    int i=100;
                    Integer i1=i;//integer i1=i Integer(i);

ex:
         int i=300;
         Integer i1=new Integer(400);
         int j=i+i1;


AUTO UNBOXING:
                          
                  The concept of geeting back the primitive data type value which is present inside wrapper class object automatically by the jvm is known as auto boxing.
                     Integer i2=new integer(200);
                      int j=i2//int j=i2.intvalue();

ex:
         int i=400;
         Integer i1=new Integer(300);
         Integer i2=i1+i;
ex:
        class wdemo2()
         {
             public static void main()
             {
              Integer i1=new Integer(100);
              Integer i2=new Integer("1234");
              Integer j=i1+i2;
              System.out.println(j);
               System.out.println("hello");
       }
     } 
output:
          1334
           hello   
              


                     

0 comments:

Post a Comment