This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Java Beans naming standards question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Java Beans naming standards question" Watch "Java Beans naming standards question" New topic
Author

Java Beans naming standards question

samir vasani
Ranch Hand

Joined: Nov 24, 2010
Posts: 59
If a java bean had a boolean variable named tankFull, how would you provide getters and setters for it ?



Options

1.) public boolean isTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

2.) public boolean getTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

3.) public boolean getTankFull(boolean tankFull){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

4.) public boolean gettankFull(){return tankFull;} public void settankFull(boolean tabkFull){this.tankFull = tabkFull;}

5.) None of the above

Please explain the answer.
Atul Shrivastava
Greenhorn

Joined: Jan 12, 2009
Posts: 19

The javaBean spec suggests that a boolean variable should have getters and setters as isXXX() and setXXX() respectively, where XXX is the name of the boolean variable.

With above logic, this option seems correct:
1.) public boolean isTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}


******************************************************************************************
2.) public boolean getTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}


3.) public boolean getTankFull(boolean tankFull){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

4.) public boolean gettankFull(){return tankFull;} public void settankFull(boolean tabkFull){this.tankFull = tabkFull;}

5.) None of the above

Please explain the answer.


OCP (SCJP) - Java 1.6
samir vasani
Ranch Hand

Joined: Nov 24, 2010
Posts: 59
Atul Shrivastava wrote:The javaBean spec suggests that a boolean variable should have getters and setters as isXXX() and setXXX() respectively, where XXX is the name of the boolean variable.

With above logic, this option seems correct:
1.) public boolean isTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}


******************************************************************************************
2.) public boolean getTankFull(){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}


3.) public boolean getTankFull(boolean tankFull){return tankFull;} public void setTankFull(boolean tabkFull){this.tankFull = tabkFull;}

4.) public boolean gettankFull(){return tankFull;} public void settankFull(boolean tabkFull){this.tankFull = tabkFull;}

5.) None of the above

Please explain the answer.



but the thing is that getXXX() is for getting the things when i want to get any value .
Then how isXXX() will work if i want to get the value?
Atul Shrivastava
Greenhorn

Joined: Jan 12, 2009
Posts: 19

both getXXX() and isXXX() are about getting the things, when you want to get a value.


its more about javaBeans naming conventions than anything else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Beans naming standards question
 
Similar Threads
boolean variable getting method keywords
JSTL over a Set: Did not get data as expected
CertPal question (JavaBean naming standards)
dynamic render?
boolean return