JavaBeans are the Java classes that have private properties. JavaBeans method standards are the standard way to access the properties of JavaBean classes.
We need to know the JavaBeans standard for SCJP in order to select the most suitable naming to access the private properties.
JavaBean Property Naming Rules:
- get/set for the property which is not Boolean type
- get/set or is/set for the Boolean type property
- get/set methods must be public
For example:
public class Foo {
private int iValue;
private boolean bValue;
private String sValue;
public int getIValue() {
return iValue;
}
public void setIValue(int value) {
iValue = value;
}
public boolean isBValue() {
return bValue;
}
public void setBValue(boolean value) {
bValue = value;
}
public String getSValue() {
return sValue;
}
public void setSValue(String value) {
sValue = value;
}
}
Java Design Pattern - Creation Pattern
16 years ago
No comments:
Post a Comment