Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question in K&B book for SCJP 1.5

 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Self Test of Chapter One: Question No.5



The answer is B, D. Why (A) is wrong? I think add is a valid prefix in Java bean convention..

The following is quoted from K&B's book for SCJP 1.5

JavaBeans methods must be named using camelCase, and depending on the method's purpose, must start with set, get, is, add, or remove.


[ July 15, 2006: Message edited by: Jon Lee ]

[ July 15, 2006: Message edited by: Jon Lee ]
[ July 15, 2006: Message edited by: Jon Lee ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is addSize is not normal usage. If it were setSize it would be OK. The add prefix would be used in addListener, for example, where you are adding to a collection of Listeners, or addObserver where you are adding to a collection of Observers in an Observable, so that they get notified of some event occuring.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addSize is not normal usage. But I think it confroms to the JavaBean convention. Does JavaBean define a valid name for a listener?? Why size cant be a name of a listener??

Hope there are no such ambiguous questions in the real exam...
[ July 18, 2006: Message edited by: Jon Lee ]
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think listener class name should end with word Listener.

I didn't have so ambiguous question in the real exam.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,

First off, Jon, the quote you used was in the summary part of the chapter! By definition, the summary can't contain all of the ins and outs - it's a summary

If you go back to page 9, you'll see that we talk in more detail about when "add" is an appropriate prefix (when it's about listeners).

Although we have indicated in the errata list that we will clarify that add is ONLY valid in the case of listeners, I think if you read page 9 you'll get the gist.

Having said that, I think the mock question is reasonable, but of course I'm always interested in feedback!

hth,

Bert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic