aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798 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 "Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798" Watch "Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798" New topic
Author

Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798

Marc Wentink
Ranch Hand

Joined: May 18, 2007
Posts: 142
Source: SCJP 5 Study Guide: Self Test Q. 12 -


12. Given two files:





And the following sub-directory structure:
test
|--UseKit.class
|
com
|--KitJar.jar


If the current directory is test, and the file pkg/Kit.class is in KitJar.jar, which
command line will produce the output bc ? (Choose all that apply.)

A. java UseKit b c
B. java UseKit a b c
C. java -classpath com UseKit b c
D. java -classpath com:. UseKit b c
E. java -classpath com/KitJar.jar UseKit b c
F. java -classpath com/KitJar.jar UseKit a b c
G. java -classpath com/KitJar.jar:. UseKit b c
H. java -classpath com/KitJar.jar:. UseKit a b c



Correct Answer as per the book: H

Shouldn't this be F & H since the classpath to the current directory is not necesarry since you are not using other classes apart from the one you start up using the 'java UseKit' command? Hence UseKit does not need any classes in the current dir?


I've read on old discussion on this subject but it is still not clear what the right answer is and if the book just contains an error here or not.

[ August 07, 2007: Message edited by: Marc Wentink ]
[ August 07, 2007: Message edited by: Marc Wentink ]

SCJP5
christian combarel
Ranch Hand

Joined: Aug 04, 2007
Posts: 47
It can't be answer F because you have to tell the JVM where to find the UseKit.class.
So, the current directory (.) must be in the classpath as it's not included by default.



-------------
Chris
Marc Wentink
Ranch Hand

Joined: May 18, 2007
Posts: 142
It can't be answer F because you have to tell the JVM where to find the UseKit.class.


I think the JVM starts from the UseKit class, and so it does not have to find it. It only has to find stuff that should be included to the UseKit class, like the instructions in the jar file.
christian combarel
Ranch Hand

Joined: Aug 04, 2007
Posts: 47
I've just tried the test (on Linux platform + JDK6.0). It confirmed that the location of the UseKit.class must be given to the JVM (answer H only).
Marc Wentink
Ranch Hand

Joined: May 18, 2007
Posts: 142
Ok. That surprises me since you can make something like a 'Hello.java' and make one class file, and call java Hello with no problems. So when does the java command need the dir of the class with main in it in the classpath?

You would say at the moment it needs a classpath to look for other stuff, it also needs the path to 'main.class' to get back again. While if you only have one file it doesn't bother to check the classpath for class files and it does not need anything?

You must admit it's a bit confusing.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Marc Wentink:
Ok. That surprises me since you can make something like a 'Hello.java' and make one class file, and call java Hello with no problems. So when does the java command need the dir of the class with main in it in the classpath? ...

For convenience, the classpath defaults to the current directory. However, once you specify a classpath, then there is no longer a default. So if you are specifying a classpath and want to also retain the current directory, then you need to include it.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798