Getter methods begin with is if the property is a boolean
Line 14 doesn't follow the JavaBeans naming conventions. Since playing is a boolean, the getter must begin with is.
Option A is incorrect because the property is of type boolean and getters must begin with is for booleans.
In addition, for boolean properties, we allow a getter method to match the pattern:
This “is<PropertyName>” method may be provided instead of a “get<PropertyName>” method, or it may be provided in addition to a “get<PropertyName>” method.
In either case, if the “is<PropertyName>” method is present for a boolean property then we will use the “is<PropertyName>” method to read the property value.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I Danilov wrote:I mistakenly first posted that to another book's errata topic. Doesn't seem there's a topic for OCA 8 study guide, so I make a new one.
I Danilov wrote:p206 table 4.5
Getter methods begin with is if the property is a boolean
K&B6 wrote:
If the property is not a boolean, the getter method's prefix must be get. For example, getSize()is a valid JavaBeans getter name for a property named "size." If the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for a boolean property.
I Danilov wrote:JavaBeans specification 1.01 final release, section 8.3.2:
Yes, I read that page. It wouldn't hurt to also specify how to report possible mistakes. I hope the way I chose is acceptable.Jeanne Boyarsky wrote:We are posting the confirmed errata here.
Jeanne Boyarsky wrote:While I don't consider this an errata, I've made a note to make this clearer if we do another edition of the book.
My getAProperty() accessor for aProperty was doomed from birth.Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names, we check if the first two characters of the name are both upper case and if
so leave it alone. So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
Thank you sir, it was thoughtless of me to forget a link.Roel De Nijs wrote:For those interested in this specification, you can download the PDF document here.
I Danilov wrote:
Yes, I read that page. It wouldn't hurt to also specify how to report possible mistakes. I hope the way I chose is acceptable.Jeanne Boyarsky wrote:We are posting the confirmed errata here.
I Danilov wrote:Certainly not an errata, but java.lang.String methods equalsIgnoreCase(), toUpperCase(), toLowerCase() are well known in some non-english speaking countries for their inconsistent behavior. equalsIgnoreCase() is implemented on assumption that converting case does not change string length (which is not true); toUpperCase() and toLowerCase() may return different results depending on locale, and yes they may change string length. There's java.text.Collator class for comparing strings in strange languages. Maybe you could consider adding this as a note for another edition. Thanks.
I Danilov wrote: Yes, I read that page. It wouldn't hurt to also specify how to report possible mistakes. I hope the way I chose is acceptable.
I Danilov wrote:Now that I read my original post, I should have stated the relation to specs clearer, sorry that it wasn't clear:
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I Danilov wrote:Off-topic:
Certainly not an errata, but java.lang.String methods equalsIgnoreCase(), toUpperCase(), toLowerCase() are well known in some non-english speaking countries for their inconsistent behavior. equalsIgnoreCase() is implemented on assumption that converting case does not change string length (which is not true); toUpperCase() and toLowerCase() may return different results depending on locale, and yes they may change string length. There's java.text.Collator class for comparing strings in strange languages. Maybe you could consider adding this as a note for another edition. Thanks.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:Scott and I both live in the United States and work on primarily English websites. So not experts in that space. I personally had no idea that changing the case could change the string length. Which is certainly interesting to know. We can only stick in so many side notes about things that aren't on the exam and try to stick to the most common ones. Plus it's probably common knowledge in whatever language has that use case. (Do you know an example of a language that works like that?)
Jeanne Boyarsky wrote:We are posting the confirmed errata here. In the book the JavaBeans discussion is just meant to be about common conventions. While I don't consider this an errata, I've made a note to make this clearer if we do another edition of the book. Thanks!
Ellen Bee wrote:The property isn't necessary the same as the instance variable/field.
Ellen Bee wrote:Therefore I think the first rule in table 4.5 is incorrect in saying "Properties are private". I think a main cause of the confusion is that rule with the example of the instance variable.
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
|