Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 4 Review Question 9 Possible Errata (Java OCA 8 Programmer I Study Guide, Sybex)

 
Andrey Belkin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is

Which are methods using JavaBeans naming conventions for accessors and mutators? (Choose all that apply)
A. public boolean getCanSwim() {return canSwim;}
B. public boolean canSwim() {return numberWings;}
C. public int getNumWings() {return numberWings;}
D. public int numWings() {return numberWings;}
E. public void setCanSwim(boolean b) {canSwim = b;}

In the answer the authors wrote that correct answers are C and E.

I agree that E is correct answer. But option C is incorrect cause it doesn't completely perform code convention. It should be:

or
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Belkin wrote:But option C is incorrect cause it doesn't completely perform code convention.

No, you are incorrect! The correct answers in the study guide are spot-on. But I definitely understand your confusion You are not the only one having doubts/confusion about this question. In this topic and this one you'll find a detailed explanation (and discussion) about this question. Definitely worth reading!

Hope it helps!
Kind regards,
Roel
 
Andrey Belkin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
No, you are incorrect!

No to no I'm correct in terms of this book.
First of all, thank you for all these (and last) links. (How do you find them so fast? I don't understand this search engine)
Yes, I see that you tell about JavaBeans specs but it really means that there is an error in table 4.5 on the page 206 when they say:

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.

So, I ask the authors to put in the errata this part of the table with a suitable comment and type of error 'Incorrect fact'.
 
Andrey Belkin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, yes, you write this correct '4.5 statement' in your reply here: https://coderanch.com/forums/posts/list/653376#3021740
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Belkin wrote:Yes, I see that you tell about JavaBeans specs but it really means that there is an error in table 4.5 on the page 206 when they say:
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.

I don't see the error. The explanation in table 4.5 is exactly what's happening here. Please note that there is a huge difference in JavaBeans specification between variable name and property. It is a good practice to have the same name for both, but it is not required.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel is correct. There's no rule that the instance variable and method name have to match. It's a good idea to not drive people crazy. But not required.
 
Andrey Belkin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne, you understand the difference between variable name and property in terms of JavaBeans, but did you write about this in your book? Where? You want confuse us, don't you? Well, this is good approach, reading the book to prepare to the exam and then go to forums to understand what you are writing about.
Errata is the correct place to make the thing clear in my understanding. Mistakes are okay, everyone make mistakes, but why don't you want to save time of other people and make this way shorter?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey,
First of all, the question you reported is already in the errrata and was originally reported here. The errata says:
#9. The correct answer is A, C and E. But if you got C and E, give yourself credit for getting it correct. The chapter text is incorrect on this, but the exam doesn’t cover this edge case. (In fact, it doesn’t cover JavaBeans at all. That is in the book, in case it is added back in).


So yes. I agree with you that mistakes should be in the errata. My response in this thread was just to reinforce Roel's explanation and not in relation to the book.  In the actual book, we use a simplified definition of JavaBeans to show common conventions with encapsulation. (And we use the term "property" loosely/incorrectly/inconsistently/in an oversimplified way. For the exam, you don't have to know anything about JavaBeans (as of right now).

There are a few places in the book where we had to simplify a concept to better match the scope of the OCA exam. It's a tough balancing act and sometimes it works better than others.
 
Andrey Belkin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see! Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic