wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B - Practice Exams book - Full Exam II - Question 21 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B - Practice Exams book - Full Exam II - Question 21" Watch "K&B - Practice Exams book - Full Exam II - Question 21" New topic
Author

K&B - Practice Exams book - Full Exam II - Question 21

Alvaro San Millan
Ranch Hand

Joined: Mar 31, 2011
Posts: 36
Hi guys,

Is someone doing these exams?

I the second full practice exam, question 21, page 204, the correct answers are D and F, but the answer F is not correct:

"When javac is invoked with a classpath option, and you need to find files in a JAR file, the name of the JAR file must be included at the end of the path."

I tried with this example:

---------------------------------------------
File A.java

public class A extends B {

static { System.out.println("A"); }

public static void main(String... args) {
System.out.println("main");
}
}

class B extends C {}

class C {}
---------------------------------------------

Current directory: temp

I compiled A.java and delete A.class, move B.class to dirB, create C.jar with C.class inside and move the C.jar to dirC, then delete C.class en temp

Final directory structure:

/temp
|---- A.java
|---- dirB
|---- B.class
|---- dirC
|---- C.jar

I tried this:

$javac -cp dirC/C.jar:dirB A.java

And the fila A.class is generated in /temp

Then, I tried:

$java -cp dirC/C.jar:dirB:. A

And the output was:

A
main

This means that the file C.jar does not need to be at the end of the path in the -cp option

Can anyone confirm me that F is not a correct answer?

Thanks in advance,

Alvaro


OCPJP 6 98%
Ash Gill
Ranch Hand

Joined: Jun 30, 2011
Posts: 71
You are correct my friend and the answer given in the book is also correct, i think you misinterpreted the answer. the following line:

"When javac is invoked with a classpath option, and you need to find files in a JAR file, the name of the JAR file must be included at the end of the path."


means that when you specify the -cp option, for eg:



now the above line has two class paths: 1) dirC/C.jar & 2) dirB A.java. the 1st classpath has a C.jar at the end of the path and if you remove it, the C.jar won't be searched for any files. so, the answer statement is not talking about the order in which class paths 1) and 2) are specified.
Alvaro San Millan
Ranch Hand

Joined: Mar 31, 2011
Posts: 36
Thanks Ash, you are right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B - Practice Exams book - Full Exam II - Question 21
 
Similar Threads
doubt in classpath
JAR file
classpath
packages doubt
classpath.