0
What is bean in java?
7 ответов
+ 2
PersonBean pb = new PersonBean();
pb.setFirstName("Subramani");
pb.setLastName("B");
+ 4
A Java Bean is just a simple class that implements the serializable interface has only a default or no argument constructor, has properties that may or may not be changed (i.e. read-write, read-only, write-only), its methods are just getters and setters and begin with get, set, or is.
Example:
package com.sololearn;
public class PersonBean implements java.io.Serializable {
private String firstName = null;
private String lastName = null;
private int age = 0;
private int height = 0;
private boolean married = false;
public PersonBean() {
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public int getAge(){
return age;
}
public int getHeight() {
return height;
}
public boolean isMarried() {
return married;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
public void setAge(Integer age){
this.age = age;
}
public void setHeight(Integer height) {
this.height = height;
}
public void setMarried(boolean married) {
this.married = married;
}
}
Java Beans are used to get, store, save (serializable), and transfer data. They are highly reusable from one project to the next.
+ 1
bean
+ 1
what
+ 1
thanks..
0
do you know?
0
can you tell, how to access from another class. simple example pls