Suppose if I've a Java source file say NitTest.java in C:\jdk1.5.0\bin directory. I compile it like below: C:\jdk1.5.0\bin>javac NitTest.java The NitTest.class file will be generated inside C:\jdk1.5.0\bin directory only by above command. Now i give following command: C:\jdk1.5.0\bin>java NitTest Hello Everyone !!
So i got the output !! My Question: On pg 768 of Kathy Sierra it is given: "When searching for class files, the java and javac commands don't search the current directory by default. You must tell them to search there. The way to tell java or javac to search in the current directory is to add a dot (.) to the classpath:" Now if that is true then how java was able to search NitTest.class in the current directory(C:\jdk1.5.0\bin)? Please remove my confusion. Thanks & Regards, Nitin
I checked Environment Variables in my OS. But I can't found a System variable or User variable that points to C:\jdk1.5.0\bin However an User Variable JAVA_HOME is there which points to: C:\jdk1.5.0 Thanks & Regards, Nitin
the reason why you don't need to specify the current directory there is the bin directory holds all the javac, java and other tools & since you can use javac that means it by default start searching from that directory.
Thanks Anuj !! One more question: If we specify -classpath when invoking java command then java only searches for the directories specified by -classpath (even if we are in C:\jdk1.5.0\bin). Is this right?