This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ]
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.
Joined: May 18, 2007
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.
Joined: Aug 04, 2007
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).
Joined: May 18, 2007
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?
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Source: SCJP 5 Study Guide: Self Test Q. 12 - Page 798