What Pojo is, what JavaBean is, and the difference between Pojo and JavaBean

Source: Internet
Author: User

Ref: 52527270

    • POJO (Plain ordinary Java object) Simple Java objects, actually is the ordinary JavaBeans, is to avoid and EJB confusion created by the abbreviation.
      The Pojo name is used to avoid confusion with EJBS, and the abbreviation is more straightforward. There are classes of properties and their getter setter methods, there is no business logic and can sometimes be used as VO (value-object) or DTO (Data Transform object). Of course, if you have a simple arithmetic attribute is also possible, However, there are no business methods, nor can we carry methods such as connection.

    • Own characteristics
      Pojo is a good acronym for plain Ordinaryjava object, but it refers to ordinary Java objects that do not use entity beans, and pojo can be used as an aid class to support business logic.
      Pojo can be understood as a simple entity class, as the name implies that the role of Pojo class is convenient for programmers to use data tables in the database, for the vast number of programmers, it is convenient to use the Pojo class as an object, of course, it is also convenient to call its Get,set method. The Pojo class also brings a lot of convenience to our configuration in the Struts framework.

    • Instance
      Pojo has some private parameters as properties of the object. The Get and set methods are then defined for each parameter as an interface for access.
      For example:

public class User {    private long id;    private String name;    public void setId(long id) {        this.id = id;    }    public void setName(String name) {        this.name = name;    }    public long getId() {        return id;    }    public String getName() {        return name;    }}

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.

  • The difference between Pojo and JavaBean
    POJO and JavaBean are 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 class of setter methods can be called Pojo, but JavaBean is much more complex than Pojo, Java beans are reusable components, there is no strict specification for Java beans, and in theory, any Java class can be a Bean. In general, however, because Java beans are created by containers (such as Tomcat), Java beans should have a parameterless constructor, and in addition, Java beans typically implement the Serializable interface to implement Bean persistence. Java beans 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 old 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).

  • The wrong understanding
    Pojo is a "pure" JavaBean in which there is nothing else in it except the methods and properties of the JavaBean specification, namely the private property and the get and set methods of public for this property method. We will find that this kind of javabean is very "simple", it can only load data, as the carrier of data storage, and not have the ability of business logic processing.

  • The real meaning
    POJO = "Plain Old Java object", a term invented by Martinfowler, is used to denote common Java objects, not JavaBean, Entitybean, or Sessionbean. Pojo does not play any special role, nor does it implement any special Java framework interfaces such as, EJB,JDBC, etc.
    That is, 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.

  • Here is a quote from Martin Fowler personal website:

    "We wondered why people were so against using regular objects on their systems and concluded that it is because simple OB Jects lacked a fancy name. So we gave them one, and it's caught on very nicely. " --martin Fowler
    We wondered why people did not like to use ordinary objects in their systems, and we came to the conclusion that ordinary objects lacked a loud name, so we gave them one and achieved good results. --martin Fowler
    Excerpt from Baidu does not know

What Pojo is, what JavaBean is, and 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.