File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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 in C:\jdk1.5.0\bin directory. I compile it like below:
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,
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 10916

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:
Thanks & Regards,
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?

[ August 17, 2007: Message edited by: Nitin Bhardwaj ]
jQuery in Action, 2nd edition
subject: Doubt in java command
Similar Threads
Down loading software
java command
Basic help
java classpath
javac not making a .class file