Java's JavaBean, EJB, and Pojo

Source: Internet
Author: User

As a start-up company, less developers, so the company temporarily decided to let a few C program ape temporary guest cameo java. So there are a lot of basic problems, today there are two people are asked me, JavaBean and pojo differences, I can follow their own understanding to their roughly said, but carefully a careful to find that they do not seem so thorough explanation is clear, looked up the next information, wrote down some notes and understanding.

1.JavaBean

JavaBean is a reusable Java component that adheres strictly to the specifications that sun defines, and JavaBean is a standard. In short, a javabean should have the following characteristics,

The > class should be public

The > property should be private, and access to the property value should be through the Getxx,setxx,isxxx method, and isxxx is used to check whether the value of the element is Boolean.

> The class should have a parameterless constructor, and the initialization of the element value is done through the Setxxx method.

> This class should be implemented with the serializable interface, this is to persist the storage needs.

For example:

Package com.example; Import java.io.Serializable; public class Bar implements Serializable {      private String name = NULL;      Private Boolean flag = false;       Public Bar () {    } public       String getName () {        return this.name;    }       public void SetName (final String name) {        this.name = name;    }       public Boolean Isflag () {        return this.flag;    }       public void Setflag (final Boolean flag) {        This.flag = flag;    
2.EJB (Enterprise Java Bean)

EJB is a Java class that runs on a EE server and is used to handle business logic, which should look like this:

> Stateful (Stateful)

> Stateless (Stateless)

> Entities (Entity)

> Message-driven bean (msg driven Beans)

Example (Stateless Bean):

 

@Statelesspublic class Employeeservicebean {    @PersistenceContext    entitymanager em;     public void AddEmployee (Employee emp) {        em.persist (EMP);}    } Read more:http://www.javaexperience.com/difference-between-pojo-javabean-ejb/#ixzz3otv2sKDE

Description: Since EJB2.0 and EJB are required to implement the Ejbobject interface and specify the type of deployment of the EJB, annotations are introduced in EJB3.0 to simplify the development steps.

3.POJO (Plain old Java Object)

A pojo is not required to implement an interface or inherit a class, nor does it have any guidance information. The biggest difference with Pojo is that it is not related to EJBS. Java is a simplified javabean, and the reason we call it a simplified bean is because it is only used to load data without the processing of the business logic. A persistent Pojo is the PO, if used in the presentation layer then it is VO.

4. Expansion 4.1. PO (Persistant object): Persisted objects

A persisted object, which can be seen as a Java object that is mapped to a table in the database. The simplest PO is a record in a table in the corresponding database, and multiple records can be used with a collection of PO. The PO should not contain any operations on the database.

4.2. VO (Value Object)

A value object is an object that contains values, such as Java.lang.Integer.VO: typically used for data transfer between business tiers, and the same as PO, which contains only data. But it should be abstracted out of the business object that can correspond to the table, or not, depending on the needs of the business. Personally feel the same DTO (data transfer object) that is passed on the web.

4.3. Dao:data Access Object

The data access object is a sun's standard Java EE design pattern. This object is used to access the database. Usually used in conjunction with PO, DAO contains various methods of operation of the database. Through its method, combine the PO to carry on the related operation to the database. Sandwiched between business logic and database resources. With Vo, provides a crud operation of the database.

4.4. Do (Domain Object )

Domain objects are tangible or intangible business entities that are abstracted from the real world.

4.5. VO (View Object )

A View object, used for the presentation layer, that encapsulates all the data for a specified page (or component).

4.6 BO (Business object)

The business logic class used to invoke DAO, and the Po and VO are joined together for business operations.

4.7.DTO (Data Transfer Object)

Used primarily for transport objects in remote calls. For example, a table of 100 fields corresponds to 100 properties in the PO, but our interface requires only 10 fields. Then we can pass a DTO with only 10 fields to the client. This does not expose the table structure to the client, and once it is associated with the interface, it is VO.

Java's JavaBean, EJB, and Pojo

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.