aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes use of javac and java commands Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "use of javac and java commands" Watch "use of javac and java commands" New topic
Author

use of javac and java commands

Ago Di Manno
Greenhorn

Joined: Jun 15, 2011
Posts: 15
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

Joined: Jan 28, 2008
Posts: 5575

Please, SearchFirst

hint: path separator is not :
Ago Di Manno
Greenhorn

Joined: Jun 15, 2011
Posts: 15
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jun 15, 2011
Posts: 15
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

Joined: Oct 02, 2003
Posts: 11406
    
  16

Seetharaman Venkatasamy wrote:hint: path separator is not :

Now that entirely depends on your OS, doesn't it?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

fred rosenberger wrote:
Now that entirely depends on your OS, doesn't it?

Huh!! you are correct!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of javac and java commands