The Container-Component Architecture allows users to extend the functionality of a container application by adding third party components. This means the management of third party components must be automated in the container. To facilitate this, the container can require all components to follow certain conventions.
A Java Bean is an ordinary Java object that follows certain conventions that make it easy for containers to manage:
It has a default constructor.
It is serializable.
Its attributes must be accessible using getter and setter methods that following a standard naming convention. This allows easy automated inspection and updating of bean state by containers, many of which include custom editors for various types of attributes.
It should not contain any required event-handling methods.
public class
PersonBean implements java.io.Serializable {
private String name;
private boolean deceased;
// No-arg constructor
(takes no arguments).
public
PersonBean() {
}
public String getName() {
return this.name;
}
public void setName(String
name) {
this.name = name;
}
// Different
semantics for a boolean field (is vs. get)
public boolean isDeceased() {
return this.deceased;
}
public void setDeceased(boolean
deceased) {
this.deceased = deceased;
}
}