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.
In the November 2005, "POJO" was used primarily to refer to Java objects that did not conform to a particular Java object model, conventions, or frameworks such as EJBS.
Ideally, a pojo is a Java object that is not subject to any restrictions (except the Java language Specification). For example a pojo should not be
1. Expand a predetermined class, such as public class Foo extends Javax.servlet.http.HttpServlet {...
2. Implement a predetermined interface, such as public class Bar implements Javax.ejb.EntityBean {...
3. Include predetermined annotations, such as @javax. Ejb.entity public class baz{...
Then, because of technical difficulties and other reasons, many compatible Pojo-style software products or frameworks actually still require the use of predetermined annotations, such as for more convenient persistence.
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.
Because these requirements are largely agreed upon rather than implemented by interfaces, many developers regard JavaBean as a pojo to comply with a particular naming convention.
In short, when a pojo is serializable, there is a parameterless constructor, and when the getter and setter methods are used to access the property, he is a javabean.
My collation and summary:
One, for Java beans, is a Java model component, which provides a standard format for using Java classes, which automatically obtains information about this class in a standard format in user programs and visual management tools, and can create and manage these classes.
Java beans can make the application more object-oriented, can encapsulate the data, the application of business logic and display logic separated, reducing the complexity of development and maintenance costs!
JavaBean is a reusable component written in the Java language. To write JavaBean, the class must be concrete and public, and have a parameterless constructor. JavaBeans exposes an internal domain as a property by providing a public method that conforms to the consistent design pattern. It is well known that property names conform to this pattern, and other Java classes can discover and manipulate these JavaBean properties through the introspection mechanism.
From the programming point of view, that is, the most basic implementation of the Get and set method of the class.
Second, Enterprise Bean, Enterprise JavaBean (EJB), is part of the Java EE, which defines a standard for developing component-based enterprise multi-application. Features include network service support and core development tools (SDKs).
In Java EE, Enterprise Java Beans (EJB) is called Java Business Bean, which is the core code of the kernel, namely the session bean, the entity bean Bean) and the message-driven bean (Messagedriven bean).
1.Session beans are used to implement business logic, which can be stateful or stateless. Each time the client requests, the container chooses a session bean to service the client. The Session bean can access the database directly, but more often, it implements data access through the entity bean. This class is typically implemented in singleton mode because it is needed for each connection.
The 2.Entity bean is a domain model object that implements the O/R mapping and is responsible for mapping table records in the database to an in-memory entity object, in fact creating an entity bean object that is equivalent to a new record, deleting an entity The bean will delete the corresponding record from the database at the same time, and when modifying an entity bean, the container will automatically synchronize the state of the entity bean with the database.
The entity bean in the Java Persistence 1.0 specification is used only as a normal Java object (POJO) and is mapped to a relational database table. Unlike other types of EJBS, entity beans can be assigned, serialized, and sent over the network like any other pojo.
The 3.MessageDriven Bean is the new enterprise Bean introduced in EJB2.0, which is based on a JMS message and can only receive JMS messages sent by the client and then processed. An MDB is actually an asynchronous, stateless session Bean that does not have to wait and return immediately after the client calls the MDB, and the MDB processes the client request asynchronously. This is suitable for situations where requests need to be processed asynchronously, such as order processing, so that the client can be prevented from waiting for a method call for a long time until the result is returned.
Iii. the difference between Enterprise Bean and JavaBean
Initially, JavaBean was designed to package standards for reusable software code. In particular, to help manufacturers develop the Java software components used under the Comprehensive Development environment (IDE). These include, for example, a grid control where users can drag and drop the part into the development environment. From then on, JavaBean can be extended to a standard part of a Java Web application, and the JavaBean part framework has been extended to the enterprise version of the Bean (EJB).
JavaBean and Server beans (often referred to as Enterprise JavaBean (EJB)) have some basic similarities. They are objects or components that are created with a set of attributes to perform their specific tasks. They also have the ability to derive additional features from the containers currently residing on the server. This makes the bean's behavior different depending on the specific task and the environment in which it is located.
JavaBean was developed using the Java.beans package, which is part of the Java 2 Standard Edition. A JavaBean is a component that runs in the same address space on a single machine. JavaBean is an in-process component. Enterprise beans are developed using the JAVAX.EJB package, which is an extension of the standard JDK and is part of the Java 2 Enterprise Edition. An Enterprise Bean is a component that runs across several address spaces on multiple machines. Enterprise beans are therefore inter-process components. JavaBean are often used as GUI widgets, while Enterprise beans are used as distributed commercial objects.
Pojo A regular Java object (not Javabean,entitybean, etc.) and does not assume any special role, nor does it implement any interface specified by the Java framework. Pojo is a simple, regular Java object that contains business logic processing or persistence logic, but not JavaBean, Entitybean, etc., without any special roles and classes or interfaces that do not inherit or implement any other Java framework.
POJO should not be the javabean we started to think of, and of course not EJB, it should not rely on the framework to inherit or implement some framework classes or interfaces. For example: Action and Actionform in Struts1 of course do not belong to Pojo, and action in Struts2 because it can not inherit any interface, so in this case the action is Pojo, But the action in Struts2 can also inherit the Actionsupport class and it will no longer belong to Pojo. Pojo can contain both business logic processing and persistence logic, as well as set and get methods similar to JavaBean properties and access to properties.
In the Baidu Encyclopedia explanation is: Simple Java object (Plain ordinary Java Objects) is actually the ordinary JavaBeans, uses the Pojo name is to avoid and the EJB to confuse, and the abbreviation compares directly. Some of these properties and their getter setter methods can sometimes be used as value Object or a DTO (Data Transform object). Of course, if you have a simple arithmetic attribute is also possible, but not allowed to have a business method, There is no way to carry a connection or something.
The difference between Pojo and JavaBean