• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Various questions regarding OCPJP

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic