wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper Classes" Watch "Wrapper Classes" New topic

Wrapper Classes

sampath garapati
Ranch Hand

Joined: Sep 26, 2005
Posts: 39
can anyone of you please give me the result for the below code and explain why. I thought the result was false and true.

public class wrappers {
public static void main(String [] ar){
Integer a,b,c=2;
a=new Integer(3);
b=new Integer(4);
int d=14;

Thanks in advance.
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
You yuorself can get result while compiling............if you have any doubt,welcome!
Richard Mendoza
Ranch Hand

Joined: Feb 26, 2003
Posts: 48

First and foremost, your program doesn't compile so how can you say that the result is false.

Please make your program runnable first.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I should run in java 1.5

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
sampath garapati
Ranch Hand

Joined: Sep 26, 2005
Posts: 39
Thank you.

May be this will run in java 1.5

haritha yellapu

Joined: Sep 06, 2005
Posts: 9
Halo Sampath!

i could execute ur program n the o/p

i would shortly get back to u with xplaination.

Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
The code will not compile in JDK1.4

Compilor error
Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
Here, c==d is equivalent to c.intValue()==d

This is because of Autoboxing/Unboxing feature present in java 1.5

Hope this helps.

- Lalitha.
haritha yellapu

Joined: Sep 06, 2005
Posts: 9
Hi All!

what lalitha has written is true!
its bcoz of autoboxing feature the comparision
is true n it is only in java1.5.

I agree. Here's the link: http://aspose.com/file-tools
subject: Wrapper Classes
Similar Threads
Wrapper Classes Autoboxing Concept
practice example for young tigers: mixing equailty and autoboxing
question about wrapper objest