File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B SCJP 6, Chapter 10 question 11 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B SCJP 6, Chapter 10 question 11" Watch "K&B SCJP 6, Chapter 10 question 11" New topic

K&B SCJP 6, Chapter 10 question 11

Marcus Moreno
Ranch Hand

Joined: Aug 17, 2008
Posts: 58

I figured out there is def. a bug in this question.

I tried it all on my own console

\test\javac -classpath MyJar.jar

\test\java GetJar
Exception in thread "main" java.lang.NoClassDefFoundError: myApp/Foo
at GetJar.main(
Caused by: java.lang.ClassNotFoundException: myApp.Foo
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more

Which does work is:
\test\java -classpath MyJar.
jar:. GetJar
Another possible way to get this done is:
\test\javac -classpath MyJar.jar
\test\javac MyApp/

\test\java GetJar

And last but not least, the simplest thing to do is:

\test\java GetJar
8 uses myApp.Foo. javac searches for it, finds a myApp/, compiles it and uses that one. java GetJar then also uses the class file instead of the jar.


Hm. I think it's somewhat "oookayish" to have errors in a book, as there are so many things to check - you will never have a book without a single error. But what about the real exam?! How can I be sure that there will not be similar errors?! You only do the exam and at the end they tell you your score, without telling you what (and why) was wrong - so you neither have any option to complain about exam bugs...


Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Yes Marcus. I also posted this problem a long time ago. Everybody agreed that this question is wrong... Although Bert never commented on this error. Let's see if he notices it this time...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Mark Gabb

Joined: Feb 03, 2008
Posts: 21
Hi all,

Is there an errata for this book being collected?

Sorry if this question has been asked in the past,

Many thanks,

Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Hi Guys,

Listen, I'm not as young as I used to be My process is to collect a few possible errata, like the one you guys are discussing, then put on my Java hat and look them all over. So, this question is on my list of things to look at - I'll let you know what I think once I've given it a good review.



Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Brad Howerter

Joined: Jan 06, 2006
Posts: 4
I guess Bert still isn't getting younger...

I don't understand why, when I run 'javac -classpath MyJar.jar' from the test directory, it creates Foo.class in the test directory. Foo.class is already in MyJar.jar!
I agree. Here's the link:
subject: K&B SCJP 6, Chapter 10 question 11
It's not a secret anymore!