my dog learned polymorphism
The moose likes Beginning Java and the fly likes javac and java -classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: javac and java -classpath
 
Similar Threads
K&B Chapter 10 Self Help Question 9
using classpath with javac Problem
Question related to Classpath when using the java and javac commands.
K&B doubt regarding question in Development chapter
classpath default settings