Forums Register Login

Development chapter - a few questions.

+Pie Number of slices to send: Send
Hey guys,

I got some question about the Development Self Test.

First of all the question number 12.



And as the right answers the F and G are listed:

F. java -classpath .:test/MyJar.jar GoDeep
G. java -classpath test/MyJar.jar:. GoDeep



but I also think that the answer C is good:

C. F. java -classpath test/MyJar.jar GoDeep


(which is the same as F and G just without the current directory to look for)

but if we are in the directory "x" then there is nothing to look for there. I mean, the GoDeep.class while executed will look for Foo.class which is accesible in test/MyJar.jar so the classpath equal to "test/MyJar.jar" should be enought, no? What do you guys think?

And another question number 11 which is cited here: https://coderanch.com/t/474863/java-programmer-SCJP/certification/Mistake-GuideBook-SCJP-Java-Chapter

I am wondering how would the correct answer look like. Why it is not C? I mean the JAR file is in the current directory so just pointing it shouldn't be bad. Or another solution I can see is something like this:



What would be the correct solution for this task? I mean besides the 4 proposed in the answer sheet.

Cheers,
Jan.
+Pie Number of slices to send: Send
javac sees the current directory by default for .java files

java looks for .class files only in the default classpath ot the classpath you mentioned......
If you do not mention . (current Directory) then it woild not be able to find GODeep.class. Hence it is mandatory .
+Pie Number of slices to send: Send
 

Sahil Kapoor wrote:javac sees the current directory by default for .java files
java looks for .class files only in the default classpath ot the classpath you mentioned......



in case of relative class paths JVM looks for current directory................
but for absolute classpath........current directory doesnot matter.........because we have to give the complete path of file
I'm so happy! And I wish to make this tiny ad happy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 785 times.
Similar Threads
Doubt: Qn 12 from K&B SCJP 6.0 chapter Development
Sun certified programmer book - chapter 10 question 12 - clarification
Questions about classpath on SCJP book.
java command: classpath or not classpath?
Doubt about Question 12 in Chapter 10 Quiz (K&B)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:04:04.