Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Question: Source Javacertexam

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


(4) Which of the following statements is false?

(A) Wrapper classes such as String,Date implement Comparable
Interface.

(B) Objects implementing Comparable interface can be used as
elements in a SortedSet.

(C) Passing a 'Comparator' to the constructor while creating
a map overrules the natural-order of a comparable object.

(D) By implementing Comparable interface the objects can specify
a 'custom' order in its elements.



My Question 1 : Are String and Date are wrapper classes?
My Question 2 : What is meant by custom order? If I am true, for this we need Comparator interface implemented by third party class.
Answer is given "D"
How long "A" is correct. I checked it thinking Date and String are not Wrapper classes.


Thanks,
cmbhatt
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as i know, wrapper classes are designed only for primitives so that object like operations can be performed on them & also to support passing them in Collections.
String & Date classes dont wrap any primitives & hence they definitely arent wrapper classes. So, i guess that the question had its answers wrong.

Second, if custom order means a class implementing Comparable interface & providing that on what factors its objects should be compared then option D is also true but if it means in how many different ways objects of a class can be compared with each other,then for that a third party class has to implement the Comparator interface & it's compare method should be invoked passing it the objects being compared. then in this case, option D would be false & hence the correct answer.
So it really depends on how "custom order" is interpreted. As far as the K&B is concerned, it says custom sort order can be implemented either ways, ie, a by implementing either Comparable or the Comparator interface. So i guess even the option D is true & hence not the correct answer.

Regards,
Sourin.

[ April 10, 2007: Message edited by: Sourin K. Sen ]
[ April 10, 2007: Message edited by: Sourin K. Sen ]
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chandra Bhatt:


My Question 2 : What is meant by custom order? If I am true, for this we need Comparator interface implemented by third party class.
Answer is given "D"
How long "A" is correct. I checked it thinking Date and String are not Wrapper classes.


Thanks,
cmbhatt



Natural Order: As imposed by Comparable intrinsically, i.e., within the class.
Custom Order: As offerred by Comparators extrinsically, i.e., Comparator implementations outside the class.

Does this throw some light on your query?
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
chandra i guess you are giving mocks,

can you please reply me about the question i have posted with name SCJP Mock TEST Doubt,as no one is replying.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stuart and Sen,

What doubt left from the Sen's part:
One thing is clear, custom means you need to arrange another way sorting, simply say customized way of sorting. Comparable is implemented by the class whose objects have to be sorted so this is the regular way what every wrapper, String and most others implement.

On the special need we create another class that implements Comparator interface to provide custom order.


Thanks again Stuart,
cmbhatt
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic