Now , as per my understanding java compiler won't search for files in current directory if it is not specified in classpath with (.). Then if we are not specifying (.) in classpath, how compiler is able to find GetJar.java?
This may sound like a silly question bu t as I am using IDE a lot for development and I have never used command prompt for compiling and executing java files, I am confused.
Could you please help me out?
Oracle Certified Professional, Java SE 6 Programmer (81%), Oracle Certified Expert, Java EE 6 Web Component Developer (87%)
-classpath is used to specify the path where the compiler will look for .class files required to compile the passed .java file. Since in the command only GetJar.java is specified then the compiler will look for GetJar.java in the current directory. The command is equivalent to
javac -classpath MyJar.jar .\GetJar.java
Even you can compile a file from a different directory by passing an absolute file path
javac command requires you to pass it a .java file name which it would compile. If you provide a relative file name then javac will automatically relate it with the current directory as would any other command which requires a file name (for example copy command or del command of windows). java command is different. java command by default looks for classes in the current directory but if you specify the classpath then it will only look for classes in the directories specified in the classpath...