Possible Duplicate:
What's the point of beans?
What is a javabean? What is it used for? And what are some code examples? I heard it is used for something to do with getter and setter methods? I'm quite confused about what a java bean is and where you even access it. I googled it but couldn't find a definite answer.
Java Bean is a normal Java class which has private properties with its public getter and setter method.
Java Beans are generally used as helper class.
Example -
public class User implements java.io.Serializable {
private String name;
private Integer age;
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public Integer getAge(){
return this.age;
}
public void setAge(Integer age){
this.age = age;
}
}
Implementing Serializable
is not mandatory but is very useful if you'd like to persist or transfer Javabeans outside Java's memory, e.g. in harddisk or over network.