• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B SCJP 6, Chapter 10 question 11

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

I tried it all on my own console

\test\javac -classpath MyJar.jar GetJar.java

\test\java GetJar
Exception in thread "main" java.lang.NoClassDefFoundError: myApp/Foo
at GetJar.main(GetJar.java:4)
Caused by: java.lang.ClassNotFoundException: myApp.Foo
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown 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
8
Another possible way to get this done is:
\test\javac -classpath MyJar.jar GetJar.java
\test\javac MyApp/Foo.java

\test\java GetJar
8

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

\test\javac GetJar.java
\test\java GetJar
8

GetJar.java uses myApp.Foo. javac searches for it, finds a myApp/Foo.java, 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...

Cheers,

Marcus
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Is there an errata for this book being collected?

Sorry if this question has been asked in the past,

Many thanks,

Mark
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks!

Bert
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess Bert still isn't getting younger...

I don't understand why, when I run 'javac -classpath MyJar.jar GetJar.java' from the test directory, it creates Foo.class in the test directory. Foo.class is already in MyJar.jar!
 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic