2018-04-30
JavaBean Specification
JavaBean is a reusable component (class) written in JAVA language.
Certain specifications must be followed:
1) Classes must be modified with public
2) Must ensure that there is a public no-argument constructor
3) Operational means including attributes ( assign the attribute <setter method>, get the attribute value <getter method> ); when using boolean type variables, the user can use isXxx() instead of getXxx(); and setXxx();
Classification:
1) Simple: domain, dao, service components, encapsulating data, operating databases, logical operations, etc. (encapsulated with fields, and provide getter and setter methods)
2) Complex: UI, such as Button, Panel, Window classes
member:
1) Method
2) Events
3) Properties
Attributes:
1) attribute: Represents state. There is no such concept in Java. Don't call member variables attributes.
2) property: represents the state, but not the field, it is determined by the operation method (getter/setter) of the property, most of which are used in the framework
Provide getter and setter methods specifically to allow the outside world to access private field members in this class
getter method: only used to get the field value
public data type getXxx(){
return Xxx;//Return field value
}
setter method: only used to set the field value
public void setXxx(parameter){
this.field = parameter; //this.field represents the field in this class
}
example:
public class Person{
//The fields of the object are used to store the object data
String name;
int age;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getAge(){
return name;
}
public void setAge(int age){
this.age= age;
}
}
在JavaBean中,只有在标准情况下字段名和属性名才相同。