Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Programmer Certification (SCJP)

Programmer Certification (SCJP) Discussion of the Sun Certified Java Programmer Exam.

what sorting algorithm comparator,comparable does?


Hai,Do we have to know what sorting algorithm comparable Interface compareTo() and comparator Interface compare() does for SCJP 5 Exam ?I Appreciate your valuable time and responsesamura

   
   

   
   
      Since these are interfaces, the methods are abstract. The API specifies that they should be implemented to return "a negative integer, zero, or a positive integer" under certain conditions -- but exactlyhowthis is done depends on the implementing class.Sorting algorithms are not part of the SCJP exam.--------------------"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer

   
   

 
   
      Sorting algorithms are not part of the SCJP, but what Comparable and Comparator are and how you use them might be part of it. (I'm not sure, lookup the SCJP exam objectives and check it yourself).--------------------Java Beginners FAQ - JavaRanch SCJP FAQThe Java Tutorial - Java SE 6.0 API documentation

   
   
   
   

      The K&B-book deals with the Comparable and Comparator interface and when my memories are right. I had a comparator question in the exam.  I also think knowledge of the implementation of these interfaces is important when you are designing your own classes and want to use these within collections, etc.--------------------Remko SCDJWS in progressSCJP 1.5, SCWCD 1.4

   
   
   
   
   
      There really is no sortingalgorithmin any implementation of Comparable / compareTo() or Comparator / compare().  Thealgorithmwould be in Collections.sort(), Arrays.sort(), TreeSet, TreeMap, and other classes thatuseComparable/Comparator.  And in any event, you don't need to know anything about what the algorithm is.[ July 07, 2007: Message edited by: Jim Yingst ]

   
   
   
 
   
      code:class GenreSort implements Comparator<DVDInfo>{public int compare(DVDInfo one, DVDInfo two){System.out.println("one" +one);System.out.println("two" +two);return one.getGenre().compareTo(two.getGenre());}}Collections.sort(dvdInfoList,gs);quote:dvdinfo.txt fileDonnie Darko/sci-fi/Gyllenhall, JakeRaiders of the Lost Ark/action/Ford, Harrison2001/sci-fi/??Caddy Shack/comedy/Murray, BillStar Wars/sci-fi/Ford, HarrisonLost in Translation/comedy/Murray, BillPatriot Games/action/Ford, Harrisonfor my understanding compare() i added print statements (which ismore confusing)output as follows: may I know what soring algorithm is use in Collection.sort(dvdInfoList,gs)oneTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  Raiders of the Lost Ark    GENRE:action  Actor :Ford, HarrisononeTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  2001    GENRE:sci-fi  Actor :??oneTITLE:  Caddy Shack    GENRE:comedy  Actor :Murray, BilltwoTITLE:  Star Wars    GENRE:sci-fi  Actor :Ford, HarrisononeTITLE:  Star Wars    GENRE:sci-fi  Actor :Ford, HarrisontwoTITLE:  Lost in Translation    GENRE:comedy  Actor :Murray, BilloneTITLE:  Caddy Shack    GENRE:comedy  Actor :Murray, BilltwoTITLE:  Lost in Translation    GENRE:comedy  Actor :Murray, BilloneTITLE:  Star Wars    GENRE:sci-fi  Actor :Ford, HarrisontwoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  Lost in Translation    GENRE:comedy  Actor :Murray, BilltwoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  Caddy Shack    GENRE:comedy  Actor :Murray, BilltwoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  2001    GENRE:sci-fi  Actor :??twoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  Raiders of the Lost Ark    GENRE:action  Actor :Ford, HarrisontwoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  Patriot Games    GENRE:action  Actor :Ford, HarrisononeTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  Caddy Shack    GENRE:comedy  Actor :Murray, BilloneTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  Lost in Translation    GENRE:comedy  Actor :Murray, BilloneTITLE:  Donnie Darko    GENRE:sci-fi  Actor :Gyllenhall, JaketwoTITLE:  Star Wars    GENRE:sci-fi  Actor :Ford, HarrisononeTITLE:  2001    GENRE:sci-fi  Actor :??twoTITLE:  Star Wars    GENRE:sci-fi  Actor :Ford, HarrisonThanks in advancesamura

   
   

 
   
      Well, as start you can look at the documentation forCollections.sort().quote:The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n log(n) performance. This implementation dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array. This avoids the n2 log(n) performance that would result from attempting to sort a linked list in place.See also:Merge Sort--------------------Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter


Related Links

About Generics and SCJP
SCJP 5 Mock Exam List
Please help
Garbage Collection
String objects
Exception:Unexpected output
mistake in k&b hashCode()/equals() contract question
hashcode and equals()
Garbage Collection
Objects eligible for garbage collection.
The return type for generics topic that I not clear.
Do Exceptions thrown are eligible for Garbage Collection?
exam Query : class relationships
Exceptions
Want to be a java developer
== primitive