• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in java command

 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is your classpath set? and if so, to what?
 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic