I am having a doubt.
My understanding is that jdk has [ jre + development tools (Java, javac, debugger etc.) + source code (src.zip) ].
Now working of java compiler is nothing to do with the running of class file.
If I am compiling a .java file then from where the java compiler is importing the package?
I could find the packages under jre.
If I do not opt to install jre while installing jdk, does that mean I will not be able to compile the java file having import statement?
Please help.
First, as a minor remark, a statement like
just introduces an abbreviation, allowing you to use the simple word
Listlater in your code instead of the full class namejava.util.List. So it's not so much the import statement itself, but the usage of a class likejava.util.Listthat needs some explanation.You understand correctly that, to compile your java file, the compiler needs some information about every class you use, and it typically finds this information in some jar file containing that class.
Now, where is this jar file containing the
java.util.Listclass that the compiler reads? You're correct, it comes from the JRE, from thert.jarthat's part of the system classpath (the Java compiler itself is a java program that needs the basic classes itself, so wherever you successfully runjavac, you always have anrt.jaravailable).If your source code used a class from some other library, you'd have to specify that library on the
javaccommand line, using an option like-cp.