Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javac and java -classpath

 
C Kushtawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic