File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JavaBeans standard method name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JavaBeans standard method name?" Watch "JavaBeans standard method name?" New topic
Author

JavaBeans standard method name?

Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
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

Joined: Feb 07, 2005
Posts: 643
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

Joined: Aug 02, 2006
Posts: 152
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.


SCJP 5.0 95%<br /> <br />The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
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

Joined: Aug 17, 2006
Posts: 36
I assume the addSize() should be addSizeListener() for it to be correct. yes?
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
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).


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Correct, addSizeListener would make a very compelling argument that your method name was correct.

Sometimes, people can be too smart.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
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


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

Joined: Aug 17, 2006
Posts: 36
Thank you all for clarifying the issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBeans standard method name?
 
Similar Threads
kathy siera book ch-1, Qstn - 2
K&B Chapter 1 Question 5
Ambiguity in Kathy Sierra Question
K&B Java 5: SelfTest Chapter 1 Q5
Wrong answer in K&B SJCP 5 self test 1.2?