Java Bean Example
what is a java bean?
A Java class with the following restrictions is called as JAVA BEAN.
1) All the data fields must be private.
2) It must have default constructor.
3) For each data fields “get” and “set” methods must be available.
example bean://employee bean
class employee{
private int id;
private String name;
public Employee(){ } //default constructor
public int getId(){ return id; }
public void setId(int id){ this.id=id; }
public String getName(){ return name; }
public setName(String name){ this.name=name; }
}
}
Advantages of Beans:
1-> Reading of form data becomes easier.
2-> Sharing of bean objects becomes easier.
3-> reusability
Yep.... I couldn't have said it better myself......