aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Various questions regarding OCPJP 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 "Various questions regarding OCPJP" Watch "Various questions regarding OCPJP" New topic
Author

Various questions regarding OCPJP

Fernando Martinez
Greenhorn

Joined: Jun 27, 2011
Posts: 12
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

Joined: Jul 19, 2011
Posts: 185
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Various questions regarding OCPJP