This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Various questions regarding OCPJP

 
Fernando Martinez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, a few questions regarding the OCPJP,

1. Suppose i have a TreeSet<MyObject>, does MyObject must implement Comparable? What happens when i try to retireve them?
2. In questions regarding ordering, unless specified otherwise, when the exam say ordered elements mean in "ascending order"?
3. Do both, java and javac commands ignore the options when stated after the .java or .class respectively? like specifing the -D option at last.
4. StringBuilder doesnt overload equals and hashcode directly form Object? I mean, why String does and Stringbuilder doesnt since it is a predefined Java class.
5. Does the following statement is true? In some places i see its true some others i read its false.
"If the GC decides to delete an object, and if finalize() has never been invoked for that object, it is guaranteed that the GC will invoke finalize() for that object before the object "


Thanks in advance,
Fernando
 
John Stark
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Suppose i have a TreeSet<MyObject>, does MyObject must implement Comparable?


The TreeSet documentation says:

public TreeSet()
Constructs a new, empty tree set, sorted according to the natural ordering of its elements. All elements inserted into the set must implement the Comparable interface.

I tried it out and when you try to add a second element of type MyObject to the TreeSet then you will get an exception if MyObject does not implement Comparable. It will compile but
then throw the exception. If you just put one element into the TreeSet then everything is fine as no ordering has to be done.

John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic