• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java and javac search logic

 
Mckenzie John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mckenzie, I would recommend you to do this experiment . believe me you will learn lot by doing this yourself .
 
Himai Minh
Ranch Hand
Posts: 1328
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic