This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes javac command (SCJP study guide book) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "javac command (SCJP study guide book)" Watch "javac command (SCJP study guide book)" New topic
Author

javac command (SCJP study guide book)

Syed Karim
Greenhorn

Joined: Dec 24, 2008
Posts: 14
Hi guys,

Relating to chap 10 of SCJP Study guide book, I can not understand the answer of 11th question:

kindly see and explain why option C is not the correct answer?,
where does " MyJar.java" comes from in explaining option C to be wrong
11. Given the following directory structure:
test-|
|- GetJar.java
|
|- myApp-|
|-Foo.java
And given the contents of GetJar.java and Foo.java:
3. public class GetJar {
4. public static void main(String[] args) {
5. System.out.println(myApp.Foo.d);
6. }
7. }
3. package myApp;
4. public class Foo { public static int d = 8; }
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:
􀀂 ✓ 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)

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Syed Karim wrote:C is wrong
because the -classpath MyJar.java in the java invocation does not include the test directory.
(Objective 7.5)

I think its typo, please refer to the K&B errata in the SCJP FAQ.
Also, as you are overwriting the -classpath settings, it won't find the "GetJar".


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Syed Karim
Greenhorn

Joined: Dec 24, 2008
Posts: 14
Thanks for the reply.

Actually I couldn't understand, is there a different rule of overriding of javac and java command?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Syed Karim wrote:Actually I couldn't understand, is there a different rule of overriding of javac and java command?

I'm talking about the "-classpath" settings getting overwritten here:

Try,

It includes the current "test" directory with the jar file in classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac command (SCJP study guide book)
 
Similar Threads
Mistake in GuideBook for SCJP Java 6.0, Chapter 10, Self Test question 11
Is this question wrong right?This question is from scjp preparation book.
Confusion over java classpath
Chapter 10 Question 11 of SCJP K and B
Doubt at K&b chapter 10,question 11