什么是POJO,JavaBean?

总结:

POJO:

一个简单的Java类,这个类没有实现/继承任何特殊的java接口或者类,不遵循任何主要java模型,约定或者框架的java对象。在理想情况下,POJO不应该有注解。

JavaBean:

JavaBean是可序列化的,实现了serializable接口

具有一个无参构造器

有按照命名规范的set和gett,is(可以用于访问布尔类型的属性)方法

pojo

POJO的创始人(martinfowler)博客:

The term was coined while Rebecca Parsons, Josh MacKenzie and I were preparing for a talk at a conference in September 2000. In the talk we were pointing out the many benefits of encoding business logic into regular java objects rather than using Entity Beans. We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely.

...在谈话中我们指出,编写业务逻辑的时候,使用常规的java对象要比实体bean要好的多。我们怀疑为什么一些人极力反对在他们的代码中使用常规对象,还辩解称因为这些常规对象没有一个花哨的名字,所以我们给他们起了一个非常好听的名字。(Plain Old Java Object)

维基百科原文————(以下代码和示例均来源于此)

The term "POJO" initially denoted a Java object which does not follow any of the major Java object models, conventions, or frameworks; nowadays "POJO" may be used as an acronym for "Plain Old JavaScript Object" as well, in which case the term denotes a JavaScript object of similar pedigree.[2]

术语POJO起初表示为不遵任何主要的java模型,约定或者框架的java对象,现在,pojo也可以用作'Plain Old JavaScript Object'的缩写,这样的话和javascript对象有着相似的渊源。

理想状态下,pojo应该是一个不受Java语言规范限制的java对象。换句话说,pojo不应该

1.继承预先设定的类,如:

public class Foo extends javax.servlet.http.HttpServlet {

// ...

}

2.实现预先设定的接口,如:

public class Bar implements javax.ejb.EntityBean {

// ...

}

3.包含预先指定的注解,如:

@javax.persistence.Entity

public class Baz {

// ...

}

However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly. The idea is that if the object (actually class) was a POJO before any annotations were added, and would return to POJO status if the annotations are removed then it can still be considered a POJO. Then the basic object remains a POJO in that it has no special characteristics (such as an implemented interface) that makes it a "Specialized Java Object" (SJO or (sic) SoJO).

然而,由于技术和其他原因,很多被称之为POJO标准的软件产品或框架仍然需要使用特定的注解来保证持久化等功能。这个想法是,如果对象(类)在任何注解添加之前是一个pojo的话,并且注解移除之后仍然是pojo。所以最基础的pojo解释是没有特别的特征(尤其是实现接口之类的),使其称之为“专用java对象”

JavaBean

A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods that follow a simple naming convention. Because of this convention, simple declarative references can be made to the properties of arbitrary JavaBeans. Code using such a declarative reference does not have to know anything about the type of the bean, and the bean can be used with many frameworks without these frameworks having to know the exact type of the bean. The JavaBeans specification, if fully implemented, slightly breaks the POJO model as the class must implement the Serializable interface to be a true JavaBean. Many POJO classes still called JavaBeans do not meet this requirement. Since Serializable is a marker (method-less) interface, this is not much of a burden.

JavaBean是一个可序列化的POJO,具有一个无参构造器,并且允许使用遵循简单命名约定的getter和setter方法来访问属性。由于这个惯例,可以对任意JavaBean属性进行简单的声明引用。使用这种声明引用的代码不需要知道bean的具体类型。并且,这个bean还可以被很多框架使用,这些java框架也不需要知道bean的类型。由于java.io.Serializable是一个标记接口(无方法),所以这并不是一个多大的负担。如果JavaBean完全实现的话,稍微打破了一些POJO模型。很多被称之为JavaBean的POJO类并不符合这个要求,因为JavaBean必须实现Serializable接口才能成为真正的JavaBean。

JavaBean的优点:

The properties, events, and methods of a bean can be exposed to another application.

A bean may register to receive events from other objects and can generate events that are sent to those other objects.

Auxiliary software can be provided to help configure a bean.

The configuration settings of a bean can be saved to persistent storage and restored.

bean中的属性,事件和方法可以暴露给另一个应用程序

一个bean可以注册来自于其他对象的事件,也可以产生事件并发送给其他对象

辅助代码可以提供javabean的配置

一个bean的配置设置可以永远被存储和恢复

一些疑问?

什么是事件?有什么作用?bean如何注册来自于其他对象的事件?

配置设置如何被存储和恢复?

serializable接口是做什么的?

pojo java_什么是POJO,JavaBean?相关推荐

  1. POJO VO PO DTO 和JavaBean

    最近在阿里手册的是突然看见PO,VO等名词发现自己还没有一个清晰的概念所以做了一些笔记. 我 给这些概念画了个关系图. pojo 为了和EJB区分而生的.就是一个简单的java对象也就是在构建这个类的 ...

  2. POJO与Entity/PO、JavaBean、DTO、BO、VO的区别与联系

    最近学习接触到了DTO,结合以前学习的entity.pojo与javaBean,不太清楚他们之间的区别与联系.看到许多博客,再加上最近工作中的一些感受总结了一下,希望能对你有所帮助 PO(Entity ...

  3. flex+hibernate 中java的pojo与as的pojo的映射问题

    今天搞flex+hibernate应遇到的pojo 与 as pojo的映射问题,呵呵,给自己做笔记.      /**    * @author timo    * 映射java端person类,属 ...

  4. java pojo使用_在POJO中使用ThreadLocal进行Java嵌套事务

    java pojo使用 大多数嵌套事务是使用EJB实现的,现在我们尝试在POJO上实现嵌套事务. 在这里,我们使用了ThreadLocal的功能. 了解嵌套事务 事务可以嵌套在另一个内部. 因此,内部 ...

  5. javabean和java类_java对象 POJO和JavaBean的区别

    一.POJO 1.定义 POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了 ...

  6. POJO,PO,JAVABEAN

    POJO = pure old java object or plain ordinary java object or what ever. PO = persisent object 持久对象 就 ...

  7. PO/BO/VO/DTO/POJO/DAO/DO

    文章目录 DO(Domain Object) DO(Data Object) PO VO BO DTO POJO DAO JavaBean EJB Entity 应用程序的分层设计 MVC 业务分层 ...

  8. DTO,VO,POJO,JavaBeans之间的区别?

    看过类似的问题: JavaBean和POJO有什么区别? POJO(普通的旧Java对象)和DTO(数据传输对象)之间有什么区别? 您还可以告诉我使用它们的上下文吗? 还是他们的目的? #1楼 Jav ...

  9. 【Spring入门学习00】Bean、POJO、DAO、BO的概念

    1.POJO POJO(Plain Old Java Object,简单Java对象),其实就是一个遵循了最简单的设计规范的Java类: 有一些private的参数作为对象的属性,然后针对每一个参数定 ...

最新文章

  1. 使用Pad Designer制作焊盘
  2. ubuntu 安装 anaconda
  3. mysql master 配置_MySQL双Master配置的方法详解
  4. 2018黄河奖设计大赛获奖_宣布我们的freeCodeCamp 2018杰出贡献者奖获奖者
  5. c++ enum 给定类型_C++11作用域内枚举enum
  6. Lua 学习笔记(四)语句与控制结构
  7. BZOJ1419: Red is good
  8. typedef 的使用
  9. 扩展卡尔曼滤波器设计
  10. 6.0后,全局悬浮窗或者弹窗不显示的解决办法
  11. 川土微电子 | 隔离电源的辐射抑制设计参考(四)
  12. 云服务预先定义正确的云计算SLA要求
  13. am3352 项目记录
  14. 数字逻辑educoder实训项目 logisim实现 交通灯系统设计
  15. Magento给Newsletter Subscribers添加状态选项(默认只有Not Activated,Subscribed,Unsubscribed,Unconfirmed)
  16. Python+Selenium PO模式Web自动化测试实战
  17. L1-007 念数字(C语言)
  18. 各地发布防病提示,秋冬不注意腹泻来敲门
  19. PowerBI中导出数据方法汇总
  20. 系统更新荣耀play服务器,EMUI9.0系统不限量升级,荣耀Play“浴火重生”,你更新了吗?...

热门文章

  1. Spring Bean名称
  2. 寻找内存泄漏:一个案例研究
  3. 通过beforeClass和afterClass设置增强Spring Test Framework
  4. Oracle Weblogic 11g(10.3.4)的小知识
  5. 在运行时交换出Spring Bean配置
  6. win7旗舰版安装不了python_怎样在Win7 64位旗舰版安装Python+Eclipse开发环境
  7. 深度学习基础实战使用MNIST数据集对图片分类
  8. sit matlab,LabView SIT工具包的使用和安装说明
  9. uni开发中可以用table标签么_「uni-app 组件」t-table 表格
  10. glup node 内存不够_Redis:内存被我用完了!该怎么办?