JavaBean
JavaBeans (TM) is a pattern for designing Java class APIs that allows instances (beans) to be used in various contexts and using various tools without explicitly writing Java code. The patterns consists of conventions for defining getters and setters for properties, for defining constructors, and for defining event listener APIs.
Basic Java Bean
Section titled “Basic Java Bean”public class BasicJavaBean implements java.io.Serializable{
private int value1; private String value2; private boolean value3;
public BasicJavaBean(){}
public void setValue1(int value1){ this.value1 = value1; }
public int getValue1(){ return value1; }
public void setValue2(String value2){ this.value2 = value2; }
public String getValue2(){ return value2; }
public void setValue3(boolean value3){ this.value3 = value3; }
public boolean isValue3(){ return value3; }}Syntax
Section titled “Syntax”- JavaBean Property Naming Rules
Remarks
Section titled “Remarks”In order for a class to be a Java Bean must follow this standard - in summary:
- All of its properties must be private and only accessible through getters and setters.
- It must have a public no-argument constructor.
- Must implement the
java.io.Serializableinterface.