• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBeans standard method name?

 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confuse by this and in need of some enlighten. I found this question in my recent SCPJ5.0 book written by the founder of this web site. Great book by the way!

Here's the question:

Which method names follow the JavaBeans standard? (Choose all that apply)
A. addSize
B. getCust
C. deleteRep
D. isColarado
E. putDimension

The correct answer is B and D. I would think A is also a correct answer, but the book shown that it's incorrect.The add prefix qualifies for JavaBeans Listener Naming Rule, which is part of JavaBeans naming standard. I assume I'm reading the question wrong, so I'll assume the JavaBeans standard is not the same as JavaBeans Listener Naming Rule? This doesn't make sense. Anyway I'm confuse, so please clarify.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following are JavaBeans standard

public void addListener()
public void removeListener()
public returnType getSomeValue()
public void setSomeValue()
public boolean isSomeValuePresent()

JavaBeans standard are applied to methods only.
JavaBeans standard are not applied to classes.
 
Javier Sanchez Cerrillo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jay. I was also in throuble with that question.

Remember the JavaBeans prefixes:
set, is, get, add and remove

Just "add" and "remove" apply to listeners. So if the following method:
addSize()

adhere to the JavaBeans naming stardards. "Size" must be a listener.

JavaBeans specification doesn't tell you if listeners must have the word "Listener" ss MyListener, or JavierListener(At least not in the book).

This is why you must "figure out" and just "figure out" listener methods have the postfix "Listener".

I think strictly speaking your anwser is correct. Because the question does't tell you if the property Size is a listener or not.
 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys! I think I got it now. For the method that applied to listener, it needs to have Listener postfix.

 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume the addSize() should be addSizeListener() for it to be correct. yes?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume the addSize() should be addSizeListener() for it to be correct. yes?


I don't think so. size is not a specialized listener subtype. It represents physical magnitude of something (i.e., how big it is).
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, addSizeListener would make a very compelling argument that your method name was correct.

Sometimes, people can be too smart.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Sorry for the confusion, if you check on the "vital k&b errata" :roll:

you'll see that we will clarify, on th enext printing of the book, that Listeners must end with "Listener"

hth,

Bert
 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for clarifying the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic