aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "questions" Watch "questions" New topic
Author

questions

kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
class X
public static void main(String args[])
String a = new String("true");
Boolean b = new Boolean(true);
if(a.equals(b))
System.out.println("true");
Compile but prints nothing. Why? Please explain in terms of the equals method.
Q2)

������17. Which statement is true for the class java.util.HashSet
A. The elements in the collection are ordered
B. The collection is guaranteed to be immutable
C. The elements in the collection are guaranteed to be unique
D. The elements in the collection are accessed using a unique key
E. The elements in the collection are guaranteed to be synchronize
ans : d ok but c is false? Isnt HashSet kinda like a Set?

thank you so much!!
sandip karmarkar
Greenhorn

Joined: Jan 08, 2001
Posts: 26
Hello Kevin
eqauls method is comparing string to Boolean object.
The first thing that equals method will check will be the type of object. If String object is getting checked for equals method to Integer or Boolean object it will return false without further check.
If String object is getting checked with another String object for equals method, then further checking of content of String will happen.
Hope it is useful.
Regards
Sandip
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi Kevin,
your second question:
D. The elements in the collection are accessed using a unique key
Isnt HashSet kinda like a Set?
Yes, it is. But You access via unique keys in M a p s. In Maps you have key-value pairs and you use a unique key to access the value.
HashSets does not have duplicate elements so they are unique, thats right, but you don't a c c e s s this elements with a unique key but with methods of Iterator class.

correct me if i am wrong
Axel


[This message has been edited by Axel Janssen (edited June 20, 2001).]
Scott Appleton
Ranch Hand

Joined: May 07, 2001
Posts: 195
I think Axel is correct. It's not clear in the original post whether d is the answer supplied with the question or whether that's Kevin's answer, but either way I think c instead of d is the correct answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions