This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrong answer in K&B SJCP 5 self test 1.2? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrong answer in K&B SJCP 5 self test 1.2?" Watch "Wrong answer in K&B SJCP 5 self test 1.2?" New topic
Author

Wrong answer in K&B SJCP 5 self test 1.2?

Saskia de Jong
Ranch Hand

Joined: Jan 24, 2006
Posts: 34
I'm sorry if this has been reported before or that I've overlooked something, but the answer to self test 1.2 in the K&B SJCP 5 book seems wrong to me.

The questions asks for compilable code. Answer B is given as:



The book says answer B is a correct answer, but unless {} is to be read as "any legal implementation", this answer is wrong. The code can't compile since there's nothing being returned.

The following would surely compile:


The following would compile if Bark had a public no-arg ctor (but we don't know):


But the code as given does absolutely not compile. Did I just miss the definition of {} for quesions somewhere?
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8805
    
    5
Hey Saskia,

You've found a big honking, gravel-hauling errata...yikes! I'm really sorry, I don't know what happened there but something got WAY out of whack with that question!

Well we posting an errata list very soon, and when we do we'll post the link in this forum.

Thanks for your help,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Saskia de Jong
Ranch Hand

Joined: Jan 24, 2006
Posts: 34
Originally posted by Bert Bates:

Thanks for your help,
Bert


You're welcome. At least thanks for the quick reply and for clearing this up

Btw, another question that I have doubts about is 1.5. It asks for valid method names according to the Javabeans standard. The answer is that 'addSize' is not correct, since 'add' is not a standard name prefix. However, 'add' certainly is a standard prefix for event listener registration.

Both the Javabean spec (section 6.5 page 29) and your book (page 9) says "add" + eventlistener type:



Now I'll agree that Size would be a strange name for an eventlistener, but I haven't seen it written anywhere that there's also a naming rule for the listener type itself. Specifically, your book makes no mention of the fact that the type names MUST end with "Listener". Therefore, when taking the self test one must assume "addSize" is a valid name.

Could you also clearify this issue?
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8805
    
    5
Hey Saskia,

I think this one isn't an errata, although I might add a sentence in the book to be a little more explicit. In section 8.4 of the JavaBean spec it states that Listener methods have to end with the literal "Listener".

hth,

Bert
Saskia de Jong
Ranch Hand

Joined: Jan 24, 2006
Posts: 34
I see. Thanks a lot Bert!

For other people who are interested in this matter, this is what the spec exactly says in 8.4:




where both methods take the same �<EventListenerType>� type argument, where the �<EventListenerType>� type extends the �java.util.EventListener� interface, where the first method starts with �add�, the second method starts with �remove�, and where the �<EventListenerType>� type name ends with �Listener�.


(emphasis added by me)
[ February 11, 2006: Message edited by: Saskia de Jong ]
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Thanks Saskia and Bert. Good information. I think there's another thread around here somewhere where they were asking pretty much the same question.

I struggled when I saw that question too, but not because of the Listener bit. I just know how common it is to have addBlah and removeBlah in the real world when you have collections of Blahs as an instance variable for a class. I just assumed that was because it was part of the Java Beans spec. After missing the question I went and read it and found the stuff that you're referring to. It's funny the things you pick up as "standards" just because you see them so often. This is making me look closer at some of these things because Java Beans standards mean a lot in the real world since a lot of tools and infrastructures are using them with reflection for working with things. Good stuff to know.

Again, thanks,
Josh
[ February 11, 2006: Message edited by: Joshua Smith ]

Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
Timothy E. Hay
Greenhorn

Joined: Jan 31, 2006
Posts: 22
Hi all,

regarding the other thread discussing Listener naming conventions, that was one of mine titled, imaginatively: "JavaBeans Listener naming conventions?" on Jan 31st, 2006.
But what Bert and Saskia have said above reiterates those comments - ie: by quoting from Section 8 in the JavaBeans API spec.

Cheers,

Tim
[ February 11, 2006: Message edited by: Timothy E. Hay ]

It's just what I reckon... ...but it's what I reckon.
 
wood burning stoves
 
subject: Wrong answer in K&B SJCP 5 self test 1.2?
 
Similar Threads
Abstract class question
Question on Abstract Class
A Question from K&B Ch 1
Doubt: K&B Self Test (Resolved and in errata)
Confused by answer provided in the Sierra and Bates book - please help