This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper Classes" Watch "Wrapper Classes" New topic
Author

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);
c*=a+b;
int d=14;
System.out.println(c==d);
System.out.println(c.equals(d));
}
}


Thanks in advance.
Sampath
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
Hi,

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


sampath
haritha yellapu
Greenhorn

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

i could execute ur program n the o/p
is:
true
true

i would shortly get back to u with xplaination.

regards,
Haritha.
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
Greenhorn

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.


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