I am trying to look under the hood about java compilation. So I laid out my IDE and started using the MS-DOS command line ...
I created a simple project, as described below in the tree:
Sampleample
|____**src** |_____pack |______Sample.java |____**classes**
This is the source code for Sample.java:
public class Sample { private String s = new String("Hello, world"); public Sample(){ System.out.println(s); } }
I just want to compile this class, so I used the javac command:
prompt\SampleApp\src>javac -d ..\classes -sourcepath . pack\Sample.java
Everything works fine, but I did not expect this because I deleted the CLASSPATH environment variable before compiling my Sample.java file. Therefore, I was expecting a compiler error due to the fact that the compiler could not find the java.lang.String class file.
I read this article http://www.ibm.com/developerworks/java/library/j-classpath-windows/ , which helped me understand a lot. The author of the article says that the default path is the current working directory. But I do not understand why my source code compiles without errors. Can anyone explain this to me?
Patrick B.
source share