Vous êtes sur la page 1sur 4

Autoboxing and Unboxing - javatpoint

http://www.javatpoint.com/autoboxing-and-unboxing

New: JAXB | Junit

Write-For-Us | Advertise Us | Ask Question | forum | login|

JavaTpoint
Home Core Java Servlet

Development | Training | SEO Promotion | Consultancy


SSS IT (Powered by Javatpoint). Visit www.sssit.org for more details.
JSP Struts2 Mail API Hibernate Spring Android Design Pattern Quiz Projects

+91-9990449935 0120-4256464

Interview Q

Comment

Forum

Basics of Java OOPs Concepts String Handling Exception Handling Nested Classes Multithreading Synchronization I/O Serialization Networking AWT Event Handling Swing LayoutManager Applet Reflection API Collection JDBC Java New Features Assertion For-each loop Varargs Static Import Autoboxing and Unboxing Enum Type Annotation RMI Internationalization The automatic conversion of primitive data types into its equivalent Wrapper type is known as boxing and opposite operation is known as unboxing. This is the new feature of Java5. So java programmer doesn't need to write the conversion code.

Autoboxing and Unboxing:

<<prev

next>>

Advantage of Autoboxing and Unboxing:


No need of conversion between primitives and Wrappers manually so less coding is required.

Simple Example of Autoboxing in java:

Output:50 5

download this example

Simple Example of Unboxing in java:


The automatic conversion of wrapper class type into corresponding primitive type, is known as Unboxing. Let's see the example of unboxing:

Output:50

Autoboxing and Unboxing with comparison operators


Autoboxing can be performed with comparison operators. Let's see the example of boxing with comparison operator:

1 of 4

9/25/2013 12:41 PM

Autoboxing and Unboxing - javatpoint

http://www.javatpoint.com/autoboxing-and-unboxing

Output:50

Autoboxing and Unboxing with method overloading


In method overloading, boxing and unboxing can be performed. There are some rules for method overloading with boxing: Widening beats boxing Widening beats varargs Boxing beats varargs

1) Example of Autoboxing where widening beats boxing


If there is possibility of widening and boxing, widening beats boxing.

Output:int

2) Example of Autoboxing where widening beats varargs


If there is possibility of widening and varargs, widening beats var-args.

Output:int int

3) Example of Autoboxing where boxing beats varargs


Let's see the program where boxing beats variable argument:

2 of 4

9/25/2013 12:41 PM

Autoboxing and Unboxing - javatpoint

http://www.javatpoint.com/autoboxing-and-unboxing

Output:Integer

Method overloading with Widening and Boxing


Widening and Boxing can't be performed as given below:

Output:Compile Time Error

<<prev

next>>

3
Google +

Tweet

118

Like

21k

javatpoint.com
Like 21,460 people like javatpoint.com.

Facebook social plugin

Like the www.javatpoint.com on facebook / google+ / twitter / subscribe to get latest updates

Tutorials
Java Tutorial
Core Java Tutorial Servlet Tutorial JSP Tutorial Mail API Tutorial

Frameworks
Struts 2.0
Struts 2 with Tiles 2 Hibernate With Struts 2 Spring With Struts 2

Interview Ques.
Core Java Servlet JSP

Forum
Ask New Ques. Latest Asked Ques.
Core Java Ques. Servlet Ques. JSP Ques. Struts Ques. Spring Ques. Hibernate Ques. Android Ques.

CONTACT US
Tel. : 0120-4256464 Mob. : +91 9990449935 Email : enquiry@sssit.org

Spring 3 Android Tutorial


Sqlite Tutorial Spring AOP Tutorial Spring with ORM Remoting With Spring Spring With Struts 2

Quizzes
Core Java quiz Servlet quiz JSP quiz

2011-2013 Javatpoint. All Rights Reserved.

Design Pattern Tutorial

3 of 4

9/25/2013 12:41 PM

Autoboxing and Unboxing - javatpoint

http://www.javatpoint.com/autoboxing-and-unboxing

Core Java DP Tutorial J2EE DP Tutorial

Hibernate Tutorial
Inheritance Mapping Collection Mapping HQL & HCQL Hibernate With Struts 2 Hibernate With Spring

Android quiz OCJP/SCWCD quiz

SSS IT PVT LTD


Development Training

Projects
Free Java Projects

OTHERS
SEO Tools

SEO Consultancy

4 of 4

9/25/2013 12:41 PM

Vous aimerez peut-être aussi