Difference between POJO and javabean

What is POJO

 According to Martin Fowler's interpretation, it is "Plain Old  Java  Object", which literally translates to "pure old-fashioned Java object", but everyone uses "simple java object" to call it.

The intrinsic meaning of POJO refers to those java objects that do not inherit from any class, do not implement any interface, and are not invaded by other frameworks.

 

 

Comparison of pojo and javabeans

The format of pojo is used for temporary transfer of data. It can only be installed in data as a carrier of data storage, and does not have the ability to process business logic.

Although the data acquisition of javabean is the same as that of pojo, there are other methods in javabean.

 

JavaBean is a reusable component written in JAVA language. Its method naming, construction, and behavior must conform to certain conventions:

 

1. This class must have a public default constructor.

2. The properties of this class are accessed using getters and setters, and other methods follow standard naming conventions.

3. This class should be serializable.

Detailed explanation:

    The POJO name is used to avoid confusion with EJB , and the abbreviation is relatively straightforward. There are some classes with properties and their getter and setter methods, which have no business logic, and can sometimes be used as VO (value-object) or dto (Data Transform Object) Use. Of course, if you have a simple operation property is also possible, but it is not allowed to have business methods, nor can it carry methods such as connection.

 

    POJO objects are sometimes referred to as Data objects, and are used extensively to represent real-world objects. If the Hibernate framework is used in the project , there is an associated xml file that makes the objects correspond to the tables in the database, and the properties of the objects correspond to the fields in the tables.

 

    POJO and JavaBean are our two common keywords, which are generally confusing. The full name of POJO is Plain Ordinary Java Object / Pure Old Java Object. It is a POJO, but JavaBean is much more complicated than POJO. Java Bean is a reusable component, and there is no strict specification for Java Bean. In theory, any Java class can be a Bean. But usually, since Java Bean is created by the container (such as Tomcat), Java Bean should have a parameterless constructor. In addition, Java Bean usually also implements Serializable interface for Bean persistence. Java Beans cannot be accessed across processes. JavaBean is a component technology, as if you made a wrench, and this wrench will be used in many places, this wrench also provides multiple functions (you can use this wrench to wrench, hammer, pry, etc.), and This wrench is a component. Generally, when creating a database mapping object in a web application, we can only call it POJO. The name POJO (Plain Old Java Object) is used to emphasize that it is a normal java object, not a special object, which is mainly used to refer to those Java objects that do not follow a specific Java object model, convention or framework (such as EJB). object. Ideally, a POJO is a Java object without any restrictions (except the Java Language Specification).

    POJO is a simple ordinary Java object, it does not contain business logic or persistence logic, etc., but is not JavaBean, EntityBean, etc., does not have any special role and does not inherit or implement any other Java framework class or interface.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325491842&siteId=291194637