Home  >  Article  >  Java  >  what is javabean

what is javabean

清浅
清浅Original
2019-05-14 14:20:048613browse

JavaBean is a special class in Java that can encapsulate multiple objects into one object. Its main function is to encapsulate data and reusable components

what is javabean

JavaBean

JavaBeans is a special class in Java , multiple objects can be encapsulated into one object (bean). It is characterized by being serializable, providing a parameterless constructor, and providing getter and setter methods to access the properties of the object. The "Bean" in the name is the idiomatic name for reusable software components used in Java.

Requirements

The attribute must be private (private String username)

Private attributes must provide get or set methods

Must provide an empty constructor (manually provide a constructor with parameters, then the empty constructor must provide manually)

Implement the Serializable interface (optional)

Function

Used to encapsulate data

Reusable components

Example: Take the 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.座位 = 座位;
}
}

What I learned at the beginning In Java, we called the above code an object class, and in the later stages, we called it a javaBean. Because in the later period, in order to facilitate the operation of data, Java usually uses objects as containers and assigns the data that needs to be operated to the objects. In order to facilitate the assignment, we must have this kind of get/set method.

The above is the detailed content of what is javabean. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn