im new to java, ROOKIE... i was doing arraylist example and i compiled it on IDE it worked perfectly, i did that example on CMD it gave me an error
Note: Practice.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
so i used my googling power and googled everything, i found a answer,
by the way this is the code im talking about...
import java.util.*;
public class Practice{
public static void main(String[] args){
ArrayList mylist = new ArrayList();
mylist.add("Maisam Bokhari");
mylist.add("Fawwad Ahmed");
mylist.add("Ali Asim");
mylist.add("Maheen Hanif");
mylist.add("Rimsha Imtiaz");
mylist.add("Mugheer Mughal");
mylist.add("Maaz Hussain");
mylist.add("Asad Shahzada");
mylist.add("Junaid Khan");
System.out.println("Name of the student: "+mylist);
}
}
it work perfectly on IDE (netbeans) but it gave those 2 errors on cmd
many people all over the internet and stackoverflow said that define the data type when creating an ArrayList object
ArrayList< String > mylist = new ArrayList<>();
i did this and it worked perfectly on CMD too... :)
now my question is this which i cant find on the internet
what is the difference between IDE compiling and command line tools compiling?
( i remember when i used to compile my C code in turboC and when i shifted to code::blocks i had to change some code to adjust the compiler , is this same thing ? but java was platform independent )
this is an interesting question, I have tried your code in the Eclipse IDE, in which it is not fine at all because Eclipse will report a warning which says:
This is why your following operation is not safe. Please see this example, if you do not specify the data type of the list, you can add any type of data in the list
So when you operate the element in the list, it will be unsafe. Does this make sense to you?