The difference between Pojo and JavaBean

Source: Internet
Author: User

What is Pojo

POJO, the full name "Plain ordinary Java Object" (also known as "Pure old Java Objects"), is literally translated as "Simple plain Java", but everyone uses "simple Java objects" to call it.

The intrinsic meaning of Pojo refers to Java objects that do not inherit from any class, do not implement any interfaces, and are not invaded by other frameworks.

Comparison of Pojo and JavaBean

The Pojo format is used for temporary transfer of data, which can only load data as a carrier of data storage without the ability to handle business logic.

JavaBean Although the data acquisition and Pojo the same, but JavaBean can have other methods.

JavaBean is a reusable component written in the Java language. Its method naming, construction and behavior must conform to a specific convention:

1. This class must have a public default constructor.

2. Properties of this class are accessed using getter and setter, and other methods conform to standard naming conventions.

3. This class should be serializable.

Detailed

The Pojo name is used to avoid confusion with EJBS, and the abbreviation is more straightforward. Some of these properties and their getter, setter method classes, have no business logic, and can sometimes be used as VO (value-object) or DTO (Data Transform object). Of course, it is possible to have a simple arithmetic attribute, but it is not permissible to have a business method or to carry a method such as connection. Pojo objects are sometimes referred to as data objects, and are used in large numbers to represent objects in reality. If the hibernate framework is used in the project, there is an associated XML file that corresponds to the table in the database, and the properties of the object correspond to the fields in the table. POJO and JavaBeanIs our common two keywords, generally easy to confuse, Pojo full name is plain ordinary Java object/pure old Java Object, Chinese can be translated into: Ordinary Java class, with a part getter/ The type of setter method can be called Pojo, but JavaBean is much more complex than Pojo, JavaBean is a reusable component, there is no strict specification for JavaBean, theoretically, any Java class can be a Bean. In general, however, because JavaBean is created by a container (such as Tomcat), JavaBean should have an parameterless constructor, and generally JavaBean also implement Serializable interfaces for implementing Bean serialization. JavaBean cannot be accessed across processes. JavaBean is a component technology, as if you have made a wrench, and this wrench will be used in many places, this wrench also provides a variety of functions (you can take this wrench wrench, hammer, pry, etc.), and this wrench is a component. in general, when building a database mapping object in a Web application, we can only call it Pojo. POJO (Plain ordinary Java object) this name is used to emphasize that it is an ordinary Java object, not a special object, which is primarily used to refer to Java objects that do not conform to a particular Java object Model, Convention, or framework (such as EJB). Ideally, a pojo is a Java object that is not subject to any restrictions (except the Java language Specification). Pojo is a simple generic Java object that does not contain business logic or persistent logic, but is not javabean, Entitybean, etc., and does not have any special roles and classes or interfaces that do not inherit or implement any other Java framework.

The difference between Pojo and JavaBean

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.