0% found this document useful (0 votes)
3 views1 page

Variables in java5

The document explains the concepts of autoboxing and unboxing in Java, where autoboxing is the conversion of primitive types to their corresponding wrapper classes, and unboxing is the reverse process. It includes code examples demonstrating these conversions, such as converting an Integer to an int and vice versa. The wrapper class in Java facilitates these conversions between primitive types and objects.

Uploaded by

patel12mmm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Variables in java5

The document explains the concepts of autoboxing and unboxing in Java, where autoboxing is the conversion of primitive types to their corresponding wrapper classes, and unboxing is the reverse process. It includes code examples demonstrating these conversions, such as converting an Integer to an int and vice versa. The wrapper class in Java facilitates these conversions between primitive types and objects.

Uploaded by

patel12mmm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Screen clipping taken: 26-01-2024 20:35

Screen clipping taken: 26-01-2024 20:33

Screen clipping taken: 26-01-2024 20:39

Screen clipping taken: 26-01-2024 20:40

Screen clipping taken: 26-01-2024 20:39

Screen clipping taken: 26-01-2024 20:42

The automatic conversion of wrapper type into its


corresponding primitive type is known as unboxing. It is the
reverse process of autoboxing.
The automatic conversion of primitive data type into its corresponding wrapper class is known as
autoboxing, for example, byte to Byte

The wrapper class in Java provides the mechanism to convert primitive into
object and object into primitive.

1 public class WrapperExample2{


Screen clipping taken: 26-01-2024 20:49 2 public static void main(String args[]){
3 //Converting Integer to int
4 Integer a=new Integer(3);
5 int i=a.intValue();//converting Integer to int explicitly
1 public class WrapperExample1{ 6 int j=a;//unboxing, now compiler will write a.intValue() internally
2 public static void main(String args[]){ 7
3 //Converting int into Integer 8 System.out.println(a+" "+i+" "+j);
4 int a=20; 9 }}
5 Integer i=Integer.valueOf(a);//converting int into Integer explicitly
6 Integer j=a;//autoboxing, now compiler will write Integer.valueOf(a) internally
7

Java Page 5

You might also like