aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript 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: 9311
    
  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