You are on page 1of 4

Autoboxing and Unboxing - javatpoint

New: JAXB | Junit

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

Home Core Java Servlet

Development | Training | SEO Promotion | Consultancy

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

+91-9990449935 0120-4256464

Interview Q



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:



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:


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


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.


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


Method overloading with Widening and Boxing

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

Output:Compile Time Error



Google +




Like 21,460 people like

Facebook social plugin

Like the on facebook / google+ / twitter / subscribe to get latest updates

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

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

Interview Ques.
Core Java Servlet JSP

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

Tel. : 0120-4256464 Mob. : +91 9990449935 Email :

Spring 3 Android Tutorial

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

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

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


Development Training

Free Java Projects

SEO Tools

SEO Consultancy

4 of 4

9/25/2013 12:41 PM