File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mock exam question" Watch "mock exam question" New topic

mock exam question

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Could somebody explain to me why this program as this behavior?
public class test {

public static void main(String[] args)
Integer a = new Integer(0);
Integer b = new Integer(0);
System.out.println(a.equals(b)); // True
System.out.println(a==b); // False
Why aren't both lines true? zero does infact equal zero correct or I am totally confused.
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
equals() checks for the exact content in the two memory locations where the two objects 'a' and 'b' are. == checks the exact memory locations where the two objects are, and if they r same it returns true. Dose it make sense ?
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Yes thank you. I've just started looking at mock exam questions and although I do program in Java quite alot I still have alot of work to do in order to get ready for the real exam. Thank you for clearing up my question.
I agree. Here's the link:
subject: mock exam question
It's not a secret anymore!