JavaBeans是Java中一种特殊的类,可以将多个对象封装到一个对象(bean)中。特点是可序列化,提供无参构造器,提供getter方法和setter方法访问对象的属性。名称中的“Bean”是用于Java的可重用软件组件的惯用叫法。
—以上源自维基百科
At first, we package an object when it comes to car object as an example:
public class car {
/**
* 这是一个五座小汽车
*/
private int 车轮 = 4 ;
private int 方向盘 = 1;
private int 座位 = 5;
public int get车轮() {
return 车轮;
}
public void set车轮(int 车轮) {
this.车轮 = 车轮;
}
public int get方向盘() {
return 方向盘;
}
public void set方向盘(int 方向盘) {
this.方向盘 = 方向盘;
}
public int get座位() {
return 座位;
}
public void set座位(int 座位) {
this.座位 = 座位;
}
}
In the beginning java learning, we put the above code is called an object class.
And a later stage, which we call a javaBean.
For ease of operation since the late java data, usually using an object as a container, the data needs to be assigned to the operation of the object, and in order to facilitate the assignment, then we must have this get / set methods.
Summarized as follows:
-
All property is private
-
Provide a default constructor
-
Provide getter and setter
-
Implement serializable Interface
Author: Sam Rainsy
from:https://blog.csdn.net/zhouvip666/article/details/83867401