2013年8月1日星期四

Pojo and JavaBean difference ( reprint )

 

OJO (Plain Old Java Object) The name used to emphasize that it is a normal java object , rather than a specific object.

 
  November 2005 when , "POJO" is mainly used to refer to those useless comply with specific Java object model , agreement or frameworks such as EJB Java objects.  
 
  Ideally speaking, a POJO is a Java object without any restrictions ( in addition to the Java Language Specification ) . For example, should not be a POJO  
 
  
       
  1. expansion scheduled classes, such as public class Foo extends javax.servlet.http.HttpServlet {...
  2.    
  3. achieve the intended interfaces, such as public class Bar implements javax.ejb.EntityBean {...
  4.    
  5. contains predefined annotation , such as @ javax.ejb.Entity public class Baz {...
  6.   
 
 
  Then , because of technical difficulties and other reasons, many software products compatible POJO style or frame in fact still requires using a predetermined dimension , such as more convenient for persistence .  
 
    
 
  Written in JAVA language JavaBean is a reusable component . Its method naming , structure and behavior must conform to certain conventions :  
 
  
       
  1. The class must have a public default constructor.
  2.    
  3. properties of this class to access using getter and setter , other methods to comply with standard naming conventions.
  4.    
  5. This class should be serializable.
  6.   
 
 
  Because these requirements mainly by convention rather than by implementing the interface , so many developers as to comply with the specific JavaBean naming conventions POJO.  
 
    
 
  In short , when a Pojo serializable , there is a no-argument constructor , use getter and setter methods to access the property, he is a JavaBean.  

没有评论:

发表评论