Why is answer C correct ?
Shouldn't the method be named "public int getNumberWings() { return numberWings }" to be JavaBean compliant (camel-case form of the property name) ?
Thanks.
Saad Benbouzid wrote:Why is answer C correct ?
Shouldn't the method be named "public int getNumberWings() { return numberWings }" to be JavaBean compliant (camel-case form of the property name) ?
Saad Benbouzid wrote:I think that's also what's explained in the JavaBean spec : http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/
See chapter 8.3 "Design Patterns for Properties".
Suresh Regmi wrote:if you look at the text book page number 206 table 4.5. It states, " The method name must have a prefix of set/get/is, followed by the first letter of the property in uppercase, followed by the rest of the property name". Then this saying is wrong.
Roel De Nijs wrote:
Suresh Regmi wrote:if you look at the text book page number 206 table 4.5. It states, " The method name must have a prefix of set/get/is, followed by the first letter of the property in uppercase, followed by the rest of the property name". Then this saying is wrong.
And could you elaborate a little bit about the reason(s) why you think this statement is wrong. For me that's a true statement!
Paul Anilprem wrote:C is correct and the statement from the book is also correct. You seem to be confusing "property" with instance variable. If your method is getNumWings, then the bean is said to have a property named numWings. The fact that it does not have numWings variable and that it has numberWings variable is irrelevant.
BTW, option A is correct as well. It is valid for a getter method for a boolean property to start with the name is or get. Both are valid.
Saad Benbouzid wrote:Can you then please explain to Suresh and me what is, in this context, the difference between an instance variable and a property ?
Saad Benbouzid wrote:
Paul Anilprem wrote:C is correct and the statement from the book is also correct. You seem to be confusing "property" with instance variable. If your method is getNumWings, then the bean is said to have a property named numWings. The fact that it does not have numWings variable and that it has numberWings variable is irrelevant.
BTW, option A is correct as well. It is valid for a getter method for a boolean property to start with the name is or get. Both are valid.
Hi Paul, thank you for your inputs.
Can you then please explain to Suresh and me what is, in this context, the difference between an instance variable and a property ?
I've read the glossary and some stackoverflows entries, but it's still unclear to me. Sometimes fields and properties are quoted interchangeably, and regarding the glossary a field is an instance variable :
http://docs.oracle.com/javase/tutorial/information/glossary.html
I'm a bit confused since I've always thought property and instance variable mean the same (and I'm actually preparing for the certification to wipe away my numerous a priori :p).
Can you please provide two snippets, as examples describing both a property and an instance variable (within the same class) .
Thanks.
Paul Anilprem wrote:BTW, option A is correct as well. It is valid for a getter method for a boolean property to start with the name is or get. Both are valid.
Saad Benbouzid wrote:Too bad you didn't provide the concrete examples I asked for
Saad Benbouzid wrote:However, for me the book must cover this statement with concrete examples, or straight delete this sentence. Suresh and I might not be the only ones wondering why C is still correct after this statement yet written in the official book.
Saad Benbouzid wrote:(Page #206, table 4.5. : "The method name must have a prefix of set/get/is, followed by the first letter of the property in uppercase, followed by the rest of the property name".)
Saad Benbouzid wrote:
Too bad you didn't provide the concrete examples I asked for
However, for me the book must cover this statement with concrete examples, or straight delete this sentence. Suresh and I might not be the only ones wondering why C is still correct after this statement yet written in the official book.
Saad Benbouzid wrote:That is to say an example involving a property + an accessor (get) complying to the "4.5 statement" + an accessor (also starting with get) not complying to the "4.5 statement".
Saad Benbouzid wrote:
But as you told me there is no concrete and proper implementation in Java regarding "property"
The method name must have a prefix of set/get/is, followed by a letter in uppercase, [eventually] followed by an alphanumeric chain of characters.
The method name must have a prefix of set/get/is, followed by the first letter of the property in uppercase, followed by the rest of the property name.
Roel De Nijs wrote:I'm starting to get the feeling I'm being ignored here!
Saad Benbouzid wrote:That is to say an example involving a property + an accessor (get) complying to the "4.5 statement" + an accessor (also starting with get) not complying to the "4.5 statement".
getNumWings is an accessor method which complies to the "4.5 statement" and getnumWings does not (although it starts with get as well!
Paul Anilprem wrote:If you have a non-private method named getXxx, you have a property named xxx
Saad Benbouzid wrote:
But then what's the meaning of this : "followed by the rest of the property name".
Saad Benbouzid wrote:Following your answer, all these four forms are correct answers, and alll these four forms follow the "4.5 statement", right ?
Saad Benbouzid wrote:Then if I understand you correctly and if we agree so far, why is the "4.5 statement" not just saying :
The method name must have a prefix of set/get/is, followed by a letter in uppercase, [eventually] followed by an alphanumeric chain of characters.
instead of :
The method name must have a prefix of set/get/is, followed by the first letter of the property in uppercase, followed by the rest of the property name.
Roel De Nijs wrote:Because the property name is not limited to alphanumeric characters, you can have properties like color1, result2, and many more
Saad Benbouzid wrote:
Roel De Nijs wrote:Because the property name is not limited to alphanumeric characters, you can have properties like color1, result2, and many more
color1 and result2 are actually of alphanumeric form Roel