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

JavaBeans naming conventions - Ch4 OCA Study Guide

 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.206 in Chapter 4 Methods and Encapsulation, Table 4.5 'Rules for JavaBeans Naming Conventions' gives the following rule:

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.

Ouestion 9 in the Review Questions on that chapter asks the following:

Which are methods using JavaBeans naming conventions for accessors and mutators?
(Choose all that apply)

One of the answers given as correct in the answers on p344 is answer C which is:


So, the property name is 'numberWings' not 'numWings'. Surely, for this answer to be correct C should be:


Or maybe some rules are just made to be broken?

Michael



 
Liutauras Vilda
Bartender
Pie
Posts: 2792
112
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure which study guide you're referring to, but I think it is a mistake if it is like that how you described.
 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's OCA: Oracle® Certified Associate Java® SE 8 Programmer I Study Guide Exam 1Z0-808 by Jeanne Boyarsky, Scott Selikoff.

The question referred to, quetion 9, is in the Review Questions at the end of Chapter 4. It looks to me like an error too, that's why I posted it.

Michael



 
Liutauras Vilda
Bartender
Pie
Posts: 2792
112
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check on official errata list, might somebody else identified that too, so your answer would get answered sooner. I don't have that book, but it seems like a simple typo, as surely getter should contain full attribute name in its name.
 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the online errata list @ selikoff.net before posting and it's not listed there.

Michael
 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I believe it is in fact correct.

In this code, the property name is numWings. The getter would be getNumWings(), and the setter would be setNumWings().

The property is stored in a field named numberWings. It could also have been named foo. The name of the field does not have to be the same as the property name, and is also not interesting from a JavaBeans perspective because the field should be private anyway.

I agree that it is confusing to name the field something different than the property, though.
 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, thanks.

 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for late reply, It is discussed here ---> https://coderanch.com/t/668643/certification/Chapter-Review-Errata-Java-OCA  ; also with reasons why A is also correct answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic