aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Chapter 10 K&B Self Test Question 11 Help 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 "Chapter 10 K&B Self Test Question 11 Help" Watch "Chapter 10 K&B Self Test Question 11 Help" New topic
Author

Chapter 10 K&B Self Test Question 11 Help

James David
Greenhorn

Joined: Mar 16, 2012
Posts: 4

Hi Guys,

I am confused about this question.

Given the following directory structure:
test-|
|- GetJar.java
|
|- myApp-|
|-Foo.java
And given the contents of GetJar.java and Foo.java:


If the current directory is "test", and myApp/Foo.class is placed in a JAR file called MyJar.jar
located in test, which set(s) of commands will compile GetJar.java and produce the output 8?
(Choose all that apply.)
A. javac -classpath MyJar.jar GetJar.java
java GetJar
B. javac MyJar.jar GetJar.java
java GetJar
C. javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar
D. javac MyJar.jar GetJar.java
java -classpath MyJar.jar GetJar

Answer is given: A is correct.

My question is why C is wrong. The answer says C is wrong because the -classpath MyJar. in the java invocation does not include the test directory. Why javac -classpath MyJar.jar GetJar.java is right? MayJar.jar doesn't include the test directory. what is the differences between javac -classpath and java -classpath? what is "java -classpath" meaning?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

When you run a javac command you specify a filename which needs to be compiled. When you provide the filename the compiler would look for that file in the current directory. But when you run the java command, you provide a class name and the class is only searched on the classpath. By default java command searches for classes in the current directory but if you provide a classpath and if it doesn't contain the current directory then java command will not look for classes in the current directory...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
James David
Greenhorn

Joined: Mar 16, 2012
Posts: 4

Thank you very much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chapter 10 K&B Self Test Question 11 Help