This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java and javac search logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java and javac search logic" Watch "java and javac search logic" New topic
Author

java and javac search logic

Mckenzie John
Greenhorn

Joined: Sep 21, 2012
Posts: 16
Hi,

I have some queries regarding the logic behind the java and javac commands searching for a class file and the jar file in the class path and also the javac command searching for the java file in the specified directories.

Assume we are in a directory A(dir A) which is a direct sub directory of root(/) which has 2 more directories named as Dir B, Dir C within it. Now we have a JavaFile.java in the Dir C.

Can you please check if my assumptions are correct with respect to the above?

a) at Dir A javac classpath:/dirA/dir C : dir A JavaFile.java - My understanding is it will search the dirC first and will be able to compile the same.

b) at Dir A javac JavaFile.java - will it still be able to find the java file as javac command will search the current directory(which will also look into the Dir C) contained in it? Please clarify

c) at Dir A javac classpath:/dir A JavaFile.java - this is similar as B because the classpath is just for classes and also javac will search for java files in the current directory. In this case if assumption b is true , this also will compile

Please clarify the above. Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi Mckenzie, I would recommend you to do this experiment . believe me you will learn lot by doing this yourself .
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 721
Mckenzie John wrote: a) at Dir A javac classpath:/dirA/dir C : dir A JavaFile.java - My understanding is it will search the dirC first and will be able to compile the same.

b) at Dir A javac JavaFile.java - will it still be able to find the java file as javac command will search the current directory(which will also look into the Dir C) contained in it? Please clarify

c) at Dir A javac classpath:/dir A JavaFile.java - this is similar as B because the classpath is just for classes and also javac will search for java files in the current directory. In this case if assumption b is true , this also will compile


a) seems correct.
b) search dir A . But it won't search dir C.
c) search current directory and then search dir A.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

i would go with Seetharaman. there are so many tiny titbits associated with the development chapter of kathy seirra and many beginners find it confusing. the only way to master is to experiment it. tinker it play with it. well this applies to other chapters as well but i have found that this chapter plagued me as well. i consulted various other resources other than kathy seirra. one hell of a good tutorial which you can read is here http://www.ibm.com/developerworks/java/library/j-classpath-windows/

also try to solve the self test questions given at the end of this chapter in kathy seirra. it would be really really helpful. and while solving them , first try to solve them bringing in all your concepts. if you are not able to then dont look at the answers. kick your favourite editor and simulate the problem and code and then again try to solve it. this approach will help you alot

Regards
Gurpreet
 
wood burning stoves
 
subject: java and javac search logic
 
Similar Threads
Question related to Classpath when using the java and javac commands.
Development
Doubt in java command
K&B Chapter 10 Self Help Question 9
Inconsistent behaviour of -classpath between java & javac