This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes javac and java -classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javac and java -classpath" Watch "javac and java -classpath" New topic
Author

javac and java -classpath

C Kushtawar
Ranch Hand

Joined: Jan 20, 2009
Posts: 37
I have modified my question and hopefully putting on the correct place.


The Sierra's book tells: "WHEN searching for classfiles the javac and java commands do not search the current directory by default."

I wanted to know whether this statement holds true only when we provide -classpath as option.


My understanding is as below:

Suppose we have a class A that extends another class B and both these files are in the same direcory /SRC.

When we invoke the following commands from the /SRC directory,it does not require the classpath to be set to current directory:

javac A.java
java A

Only when we put -classpath as option then we need to give current directory as the path to search as below:
javac -classpath . A.java
java -classpath . A

Please let me know if my understanding is correct.If the option classpath is not provided the current directory will always be searched for class files.


Regards,
Chandan

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

C Kushtawar wrote:The Sierra's book tells: "WHEN searching for classfiles the javac and java commands do not search the current directory by default."

I wanted to know whether this statement holds true only when we provide -classpath as option.


That completes the story itself. You are right. This only applies if you use -classpath as an option or you have set the classpath environment variable...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac and java -classpath
 
Similar Threads
K&B doubt regarding question in Development chapter
using classpath with javac Problem
Question related to Classpath when using the java and javac commands.
K&B Chapter 10 Self Help Question 9
classpath default settings