This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Chapter 1 Question 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "K&B Chapter 1 Question 5" Watch "K&B Chapter 1 Question 5" New topic
Author

K&B Chapter 1 Question 5

B Bhalla
Greenhorn

Joined: Mar 18, 2009
Posts: 14
5. Which method names follow the JavaBeans standard? (Choose all that apply.)
A. addSize
B. getCust
C. deleteRep
D. isColorado
E. putDimensions

I thought A, B and D are correct. However they say only B and D are correct.

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

What am I missing? Why is "add" not a correct answer here?
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
add and remove are for listeners; get, set, and is are for instance variables
B Bhalla
Greenhorn

Joined: Mar 18, 2009
Posts: 14
Ryan Beckett wrote:add and remove are for listeners; get, set, and is are for instance variables


Thanks and agreed. But where does it mention "instance variables" in the question? All it is asking is valid method names based on JavaBeans Standard.
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
isn't it add and remove are just for Listeners


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192



User and Pass are instance variables.
B Bhalla
Greenhorn

Joined: Mar 18, 2009
Posts: 14
Ryan Beckett wrote:


User and Pass are instance variables.


Thanks. But I am really not clear of the point that you are trying to make. Where does the question mention "instance variable"?

Again. I really appriciate all the feedback and help here..
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
Im talking about the naming conventions. Basically the beans are done in a standard way.



K & B are saying that this is the proper way to do it. There's nothing left to misunderstand.
If you want to know more about instance variables I'd suggest you sift through chapter 1.

I said instance variable because you must know the name of it when you create your function.
Since my instance variable's name is 'name' my method has to be 'getName'. Not 'getname',
'Getname', or 'GetName'.

Edit:

I just remembered its referred to as a 'property'. Sorry for the confusion.
B Bhalla
Greenhorn

Joined: Mar 18, 2009
Posts: 14
I am not sure why I am having such a great difficulty in explaining my question. Let me try to rephrase it...

The question asked in the book is as follows. I do not see any mention of the word "Instance Variable" (or Listener) in this question. So, why and how should I assume that the author of the question wants me to identify standard naming convention for a "Instance Variable" method? Why should I not say that addSize is a correct answer, assuming that Size is my Listener's name (however add it might sound!!).

5. Which method names follow the JavaBeans standard? (Choose all that apply.)
A. addSize
B. getCust
C. deleteRep
D. isColorado
E. putDimensions
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
whenever you use add or remove as method name..it should have Listener word associated.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8717
Hey B,

You probably have a slightly older version of the book. We added a couple of sentences of clarification in the newest printing. In a nutshell, the only time that "add" is a valid JavaBean prefix is when it is used with a Listener.

hth,

Bert


Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
B Bhalla
Greenhorn

Joined: Mar 18, 2009
Posts: 14
Thanks Bert and Himalay. Both of you clarified my doubts.

Thanks to others who answered too. I am clear about this now.

Starting chapter 2 now.. Hope to finish it off by Tuesday or Wednesday. Will be back with more questions!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Chapter 1 Question 5
 
Similar Threads
An error in the K&B SCJP5 book?
K&B Java 5: SelfTest Chapter 1 Q5
Error in Book "SCJP Study Guide for Java 5" ?
Ambiguity in Kathy Sierra Question
contradictory statements