• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

boolean primitive type in JavaBean standard.

 
Greenhorn
Posts: 2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it ok to start getter method for boolean with 'get' instead of 'is' in JavaBean standard? Some articles online says only to use 'is' for boolean getter methods.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

"get" is fine but "is" makes your code more readable, IMO. It also depends on the semantics of your boolean method. Read your code out loud and try to use a name that makes your code more conversational and is semantically/grammatically correct in the context where it's used.


As you see in example 2, the standard "get" prefix does not fit the semantics of the usage nor does the "is" prefix that your articles recommend. The prefix "has" makes more sense here and makes the code easily understandable. If course, you could choose another name where "is" will make more sense:
 
Rohit Khatkar
Greenhorn
Posts: 2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am preparing for OCP exam. From exam point of view both 'is' and 'get' are right ? or just 'is'?
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Technically, either one is fine as far as JavaBean conventions although "is" is preferable. I suppose that's good enough for the exam but don't take my word for it. Others who are more savvy about the nuance in the context of the OCP exam will probably chime in. I still think that you need to consider grammar and semantics when you choose an answer, at least that's what I would do if I were taking the exam. It all depends on what name they give you in the exam, doesn't it?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic