Hi ranchers!
At Sybex book on OCA by Jeanne and Scott at page 206 there's a JavaBeans naming convenctions rules sum up.
They seemed easy and clear to me.
But when I got the relative review question ( n. 9 ) on these convenctions I miserably failed.
So I wanted to make a recap of these rules like I understood it. And make some questions
- Instance variables must be private.
But static ones?
- Getters: if the property is a boolean must begins with
is OR
get. ie:
public boolean isHappy(){return happy;} OR
public boolean getHappy(){return happy;}.
Can you give me a confirmation about boolean getters?
if the getter is another about
java type it must begins with
get only.
- Setter methods begins with
set. ok
The rest of the name for getters and setters is the name of the property encapsulated beginning whith capital letters:
So for example we have a property called
numberOfExams the getter and setters must be called
getNumberOfExams() and
setNumberOfExams;
but names that shorten the original one one are valid as well?
getNumOfExams() and
setNumOfExams; are also valid for JavaBean naming convenctions?
Hope you'll make me clear.