This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In one of my java prg based on collections on compliling my IDE(JCreator 2.5 LE) shows following output :- --------------------Configuration: JDK version 1.5.0 <Default>-------------------- Note: F:\LEARN\JAVA APPS\EXPERIMENTS\CompDemo1.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Process completed.
The programs runs Completely!...no prb with prg just, whats the meaning of it (....i.e "unchecked or unsafe operations" )? B'coz i had never heard of such terms "unsafe" or "unchecked" in Java, they are in C# !
one more thing ......how does the integer value obtained from my userdefined comparator is used by the tree set " EXACTLY! " ?
Can comparison using comparator be only " = ", " <= ", " >= " ?....i mean when we have operators, why is their a separate need of comparators ?
i have some more dbts in Collections (...in java alltogether) , Hope the moderator does not think of my dbts as burst of interview dbts ! Please! Am trying to get deep down in java on my own by refering books and when they are unclear i make a list and ask them, javaranch does not allow me to ask the list of dbts in one thread else...i would have!
Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
This is "unsafe" because of that cast. In Java 1.5, you have generics, which allow you to write this:
ArrayList<String> list = new ArrayList<String>(); list.add("foo"); String s = list.get(0);
Note there is no more cast. Google for "Java generics" to find lots of information on this topic.
As to your second question, the operators you list don't work on Objects, only on numbers, right? So you need Comparators or Comparables to provide ways of comparing Objects.
The integer returned by a Comparator is used by a TreeSet to put objects in order. If the number is positive, one object should come first; if it's negative, then the second should be first. If it's zero, they're the same.