File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Doubt in my Java prg Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Doubt in my Java prg" Watch "Doubt in my Java prg" New topic

Doubt in my Java prg

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
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\ uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Process completed.

The programs runs Completely! 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 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 ( 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][/url] | [url][/url]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

The warning message means that in at least one spot, you're using a Collection in the "old" (before 1.5) way:

ArrayList list = new ArrayList();
String s = (String) list.get(0);

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>();
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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Doubt in my Java prg
It's not a secret anymore!