Monday, 22 February 2016

Java Tutorial : Java wrapper class(Autoboxing and unboxing)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=VMr3oaalVoE&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java wrapper class(Autoboxing and unboxing) 
Java Tutorial : Java wrapper class(Autoboxing and unboxing) 
PrimitiveToWrapperExample.java
public class PrimitiveToWrapperExample
{

    public static void main(String[] args)
    {

        /*
         * Primitive to Wrapper Example.
         * 
         * Converting int into Integer
         */

        int intValue = 300;
        Integer integerObj1 = Integer.valueOf(intValue);

        System.out.println("integerObj1 = " + integerObj1);

        /*
         * Autoboxing, now compiler will write
         * Integer.valueOf(a) internally
         */

        Integer integerObj2 = intValue;
        System.out.println("integerObj2 = " + integerObj2);

    }
}
Output
integerObj1 = 300
integerObj2 = 300
WrapperToPrimitiveExample.java
public class WrapperToPrimitiveExample
{

    public static void main(String[] args)
    {
        /*
         * Wrapper to Primitive
         * 
         * Converting Integer to int
         */
        Integer integerObj = new Integer(3);
        System.out.println("integerObj = " + integerObj);

        /*
         * converting Integer to int
         */
        int i = integerObj.intValue();
        System.out.println("i = " + i);

        /*
         * Unboxing, now compiler will write a.intValue()
         * internally
         */
        int j = integerObj;

        System.out.println("j = " + j);

    }

}
Output
integerObj = 3
i = 3
j = 3
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/WrapperClassDemo_Autoboxing_Unboxing_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/WrapperClassDemo_Autoboxing_Unboxing_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d0559102086f9677d57877fbba43556aca45fc19/BasicJava/WrapperClassDemo_Autoboxing_Unboxing_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • 2 comments: