java2db

Autoboxing and Unboxing in java



Autoboxing and Unboxing is a automatic conversion , that makes java compiler between primitives and its corresponding wrapper classes . See the below list .

Autoboxing and Unboxing

Difference between Autoboxing and Unboxing :

Autoboxing :

Autoboxing and Unboxing Converting a primitive type to its corresponding Wrapper class is called autoboxing .

Example for Autoboxing :

 

Autoboxing and Unboxing Constructor autoBoxing with two parameters  Integer and int (line 4). But we are passing  int and

……..int (line 18) . So  The JVM  converts int value to Integer  object with new Integer(int) method .

Autoboxing and Unboxing In line 9 , adding primitive int values to Integer generic List .

 

Unboxing :

Autoboxing and Unboxing Converting a wrapper class to its corresponding primitive type is called unboxing .

Example for Unboxing :

 

Autoboxing and Unboxing Constructor unBoxing with one parameter int (in line 4) . But we are passing Integer object as an

…….argument (in line 19) . So the JVM converts Integer object to int internally with

…….new unBoxing(val.intValue())  method .

Autoboxing and Unboxing In line 12 , adding int value and Integer value.

This way the  JVM takes care of Autoboxing and Unboxing in java .




Related Posts :

Comments

  1. Sakthivel says:

    Clear notes. Thanks

   [will not be published]



^ <