Here is a brief explanation about the characteristics of java bean classes.
We create a java bean class to represent a table in data base.
And the characteristics of java bean classes should be as follows.
1.class should be public
2.Attributes(fields) should be private
3.Constructor should be private
4.And at least there must be two constructors. The default constructor and the constructor which represent all the attributes by it's parameter list.
and the setters(mutator) and getters(accessors) should be public.
An example for java bean class:
public class Student{
private String stud_id;
private String stud_name;
private String stud_address;
public Student(){
}
public Student(String stud_id,String stud_name,String stud_address){
this.stud_id=stud_id;
this.stud_name=stud_name;
this.stud_address=stud_address;
}
public void set_stud_id(String stud_id){
this.stud_id=stud_id;
}
public String get_stud_id(){
return stud_id;
}
public void set_stud_name(String stud_name){
this.stud_name=stud_name;
}
public String get_stud_name(){
return stud_name;
}
public void set_stud_name(String stud_address){
this.stud_address=stud_address;
}
public String get_stud_address(){
return stud_address;
}
}
No comments:
Post a Comment