• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Doubt in java command

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13069
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic