• 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

A question in K&B book for SCJP 1.5

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic