Difference between compiling a command line tool and compiling a Java IDE

im new for java, ROOKIE ... i was doing an arraylist example and i compiled it in IDE it worked fine i made this example in CMD it gave me error

Note. Practice.java uses untested or unsafe operations.

Note. Recompilation with -Xlint: unchecked for details.

so i used my googling ability and everything googled i found the answer,

by the way, this is the code I'm 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 works fine on IDE (netbeans) but it gave these 2 errors on cmd

many people all over the internet and stackoverflow said they define the datatype when creating an ArrayList object

ArrayList <String> mylist = new ArrayList <> ();

I did this and it worked great on CMD ... :)

now my question is what I cannot find on the internet

What is the difference between IDE compilation and command line compilation?

(I remember when I used to compile my C code in turboC and when I moved to code :: blocks I had to change the code to set up the compiler, it's the same, but java was platform independent)

+3


source to share


3 answers


This is an interesting question, I tried my code in the Eclipse IDE where it doesn't work at all, because Eclipse will report a warning that says:

Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized

      

This is why your next operation is not safe. In this example, if you do not specify the data type in the list, you can add any data types to the list



 List a = new ArrayList();
 a.add("abc"); //add a string object
 a.add('a'); //add a char
 a.add(1); // add a integer

      

Therefore, when you manipulate an item in the list, it will be unsafe. Does this make sense to you?

+1


source


One reason for the difference is that your IDE might be using a different java version than your command line compiler. You will see this if your Netbeans IDE is using java 1.4 or later and your command line is using 1.5 or later.



+2


source


Your IDE will report the same, depending on the compiler version. To my recollection, Java 1.4 will not report this as a problem, but 1.5 and later versions will involve going against the grain of generics.

Done correctly, there is no difference between compilation done on the command line and compilation done by the IDE. But that means you have to be sure that the same Java version is being used to compile the code two times later.

+2


source







All Articles