aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11 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 "Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11" Watch "Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11" New topic
Author

Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11

Tomasz Sadura
Greenhorn

Joined: Dec 14, 2009
Posts: 1

Given the following directory structure:

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.)


Answer:
A is correct. Given the current directory and where the necessary files are located, these
are the correct command line statements.

B and D are wrong because javac MyJar.jar GetJar.java is incorrect syntax. C is wrong
because the -classpath MyJar.java in the java invocation does not include the test directory.
(Objective 7.5)


The A answer is not correct, because the Foo class cannot be found when executing the GetJar. None of the answers is correct.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Hi Tomasz, welcome to javaranch.

This error has been noticed before and has been reported here. You can submit any other error that you find in the book in that topic created by Bert Bates...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Justin Fleming
Greenhorn

Joined: Dec 30, 2009
Posts: 10
I'm having trouble with this one too.

The other thread linked above says "GetJar refers to "Foo.d" but does not either import myApp.* or refer to Foo.d by its fully qualified name. There is no way to get this code to compile." That is not the case in my book, or in the OP's (Original Poster). My book also has the following which uses the fully qualified name.



Furthermore, option "A" compiles the code fine on my machine, so long as the directory structure is preserved in the Jar file.

The jar can be created with after compiling the the java file using
javac -classpath MyJar.jar GetJar.java
jar -cf myJar.jar myApp/Foo.class


However my issue is that the explanation for option C seems incorrect.


1st) there is no "MyJar.java" in option C. It should be "MyJar.jar"
2nd) even if it was written correctly I would take this to mean

java -classpath test/Myjar.jar GetJar

which is not the reason it would not work.

3rd) I think what it is trying to say is that the Jar file (MyJar.jar) does not include the GetJar.class file (which is in the test directory).

A jar that contains this file can be created using the following command. This will allow option C to run and be correct as well. But it was not specifically said that these files were or were not in the Jar file.

jar -cf MyJar.jar GetJar.class myApp/Foo.class

or

jar -cf MyJar.jar *

So really C could also be correct, unless we assume that the only class in the Jar is myApp/Foo.class
perhaps giving the jar file creation command (and location executed) in place of the statement that "myApp/Foo.class is placed in a JAR file called MyJar.jar" would be much more clear.
Karol Kornecki
Greenhorn

Joined: Nov 03, 2009
Posts: 14
Hi

I think the correct answer should be:



or



when I compile and run the program as above it prints 8.


Sun Certified Programmer for Java Platform 6.0 (96%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11