File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Wrapper" Watch "Wrapper" New topic
Author

Wrapper

Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75
Integer i1=100;
Integer i2=new Integer(100);

What is the difference between these two Statements?
Can anyone Please Explain.Thanks


SCJP 5
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The second statement explicitly creates a new wrapper instance. But the first statement uses boxing, which either implicitly creates a new wrapper instance, or (because the value is within the range of a byte) references an existing instance. See JLS 5.1.7 for details.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Wrapper
 
Similar Threads
Wrapper class doubt
== , autoboxing Doubt
are these one and the same
Changing int into object
Object References & GC