Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JavaBeans naming conventions - Ch4 OCA Study Guide

 
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



 
Marshal
Posts: 7187
492
Mac OS X VI Editor BSD Linux
  • 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
Marshal
Posts: 7187
492
Mac OS X VI Editor BSD Linux
  • 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
 
Saloon Keeper
Posts: 10682
229
  • 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.

 
Bartender
Posts: 1245
86
Hibernate jQuery Eclipse IDE Angular Framework Spring MySQL Database AngularJS Tomcat Server Java
  • 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.
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!