wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in java command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in java command" Watch "Doubt in java command" New topic
Author

Doubt in java command

Nitin Bhardwaj
Ranch Hand

Joined: Feb 02, 2007
Posts: 72
Dear Friends,

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
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

is your classpath set? and if so, to what?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nitin Bhardwaj
Ranch Hand

Joined: Feb 02, 2007
Posts: 72
Hi Fred,

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
anuj bhatnagar
Ranch Hand

Joined: Aug 06, 2007
Posts: 31
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 & regards,<br />Anuj Bhatnagar
Nitin Bhardwaj
Ranch Hand

Joined: Feb 02, 2007
Posts: 72
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?

Regards,
Nitin
[ August 17, 2007: Message edited by: Nitin Bhardwaj ]
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in java command