aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Master Exam Question 68 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 "K&B Master Exam Question 68" Watch "K&B Master Exam Question 68" New topic
Author

K&B Master Exam Question 68

Tyronne Fernando
Ranch Hand

Joined: May 11, 2008
Posts: 50
The following question is from the K&B Master Exam CD (Question 68)

If three versions of MyClass.java exist on a file system:
Version 1 is in /foo/bar
Version 2 is in /foo/bar/baz
Version 3 is in /foo/bar/baz/bing

And the system's classpath includes the following:
/foo/bar/baz

Which command line(s) will use Version 2 of MyClass.java? (Choose all that apply)

A javac -classpath /foo/bar:/foo/bar:. MyClass.java
B javac -classpath /foo/bar/baz:/foo/bar MyClass.java
C javac -classpath /foo/bar/baz/bing:/foo/bar:. MyClass.java
D javac -classpath /foo/bar/baz/bing:/foo/bar/baz MyClass.java
E The result is not predictable

B is given as the correct answer.

If I am correct the classpath is only used to search for .class files. If that is the case none the above answers are correct. Please let me know whether I am right or wrong.

Thanks.
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
the compiler also needs to know classpaths.
How else could it find the standard libraries?
If you have a program that imports other classes you wrote
that are in packages, how else would the compiler find them?
As well as the java launcher, the compiler also needs classpaths.

For the above question, you need to omit the system classpath, as this is overridden by a command line -classpath switch.
And finally, remember that /foo/bar/baz is an absolute path, not a relative path, so the compiler looks in the baz directory, which resides at /foo/bar/baz.
Best regards.

[ July 27, 2008: Message edited by: Keith Nagle ]
[ July 27, 2008: Message edited by: Keith Nagle ]

SCJP 5.0
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
so the compiler looks in the baz directory, which resides at /foo/bar/baz.
Yes, but what is the compiler looking for ? In my understanding it is looking for class files as the option -classpath indicates and not for source files. For the source file MyClass.java it will just look in the current directory, if the command is

javac -classpath /foo/bar/baz:/foo/bar MyClass.java

Perhaps the given choices should better be

A) java -classpath /foo/bar:/foo/bar:. MyClass
B) ...

Then the answer in K&B would be correct.
[ July 27, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
I tested this out, and javac does not search the classpath for .java files. Only the current directory. You have to specify where MyClass.java is, unless it's in the current directory. So isn't the question incorrect?
[ July 27, 2008: Message edited by: Eric Daly ]

Studying for SCJP 6
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
The question must be wrong.
Assume that we are working with class files instead (MyClass.class)
of .java source files and answer b is correct,
also assuming we use the java launcher instead of javac.
Classpaths on the command line override the system variable
classpath and it will also evaluate the classpath from left to right.
Regards
[ July 27, 2008: Message edited by: Keith Nagle ]
Tyronne Fernando
Ranch Hand

Joined: May 11, 2008
Posts: 50
Thanks. My assumption was the same that the question is wrong. Hope they will fix this in K&B.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Master Exam Question 68