File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Beans naming standards question

 
samir vasani
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
Eclipse IDE Firefox Browser Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
samir vasani
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
Eclipse IDE Firefox Browser Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic