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

use of javac and java commands

 
Ago Di Manno
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have some problems when I try to answer questions regarding the use of javac and java commands because I'm not able to find a definitive rule for them:

so far I have understood that:

javac: first the compiler has to be able to find the file to compile, and then in the classpath it has to find every file necessary for compiling.

java: in the classpath I have to find the file to execute and any other file necessary for executing. This command doesn't look in the current directory by default.

So, if I try to do the exercise 11, page 829 of K&B, the correct answer is A because:

in this command the compiler is able to find the file to compile (GetJar.java) because it looks in the current directory by default, and it is able to find Foo.class thanks to the classpath that points a jar.


Why is this correct? I would write in order to find both Foo.class and GetJar.class in the test directory...
How can I execute without looking into the "test" directory and into the .jar???

Can someone help me or correct me..I'm finding very hard to understand this part...despite of it looks like one of the simpliest part!

Thanks Guys



 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, SearchFirst

hint: path separator is not :
 
Ago Di Manno
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tryed to search with a lot of different key words before posting...without finding anything useful...

I can't find any explanation using your hint..and my question is not related to path separator...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ago Di Manno wrote:
java: in the classpath I have to find the file to execute and any other file necessary for executing. This command doesn't look in the current directory by default.

you are absolutely right! but what I was saying is you need to include the current directory also in classpath as in
java -classpath MyJar.jar;. GetJar note here *I replaced : with ;* you can have many path location in your classpath.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ago Di Manno wrote:I tryed to search with a lot of different key words before posting...without finding anything useful...

http://www.coderanch.com/how-to/java/HowToSetTheClasspath
 
Ago Di Manno
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:
Ago Di Manno wrote:I tryed to search with a lot of different key words before posting...without finding anything useful...

http://www.coderanch.com/how-to/java/HowToSetTheClasspath


Firstly, thanks for your replies!
So, you agree with me! I need to specify the current directory in the classpath, but in the exercise mentioned above, the correct answer is

How can it function?It shouldn't execute...or not?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:hint: path separator is not :

Now that entirely depends on your OS, doesn't it?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Now that entirely depends on your OS, doesn't it?

Huh!! you are correct!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic