JavaBean的任务就是: “Write once, run anywhere, reuse everywhere” Enterprise JavaBeans

javaBean_百度百科 https://baike.baidu.com/item/javaBean/529577?fr=aladdin

区别EJB

JavaBean 和 Server Bean(通常称为Enterprise JavaBean(EJB))有一些基本相同之处。它们都是用一组特性创建,以执行其特定任务的对象,获得其它特性的能力。这使得 bean 的行为根据特定任务和所在环境的不同而有所不同。
Enterprise Bean 与 JavaBean 不同。JavaBean 是使用java.beans包开发的,它是 Java 2 标准版的一部分。JavaBean 是一台机器上同一个地址空间中运行的组件。JavaBean 是进程内组件。Enterprise Bean 是使用 javax.ejb 包开发的,它是标准JDK的扩展,是 Java 2 Enterprise Edition 的一部分。Enterprise Bean 是在多台机器上跨几个地址空间运行的组件。因此 Enterprise Bean 是进程间组件。JavaBean 通常用作 GUI 窗口小部件,而 Enterprise Bean 则用作分布式商业对象。
 
JavaBean 是一种JAVA语言写成的可重用组件。为写成JavaBean,类必须是具体的和公共的,并且具有无参数的构造器。JavaBean 通过提供符合一致性设计模式的公共方法将内部域暴露成员属性,set和get方法获取。众所周知,属性名称符合这种模式,其他Java 类可以通过自省机制(反射机制)发现和操作这些JavaBean 的属性。
软件名称
JavaBean
开发商
SUN
软件语言
Java
属    性
可重用组件
使用规范
JSR

 

一个JavaBean由3部分组成:
  
  (1) 属性(properties)
  JavaBean提供了高层次的属性概念,属性在JavaBean中不只是传统的面向对象的概念里的属性,它同时还得到了属性读取和属性写入的API的支持。属性值可以通过调用适当的bean方法进行。比如,可能bean有一个名字属性,这个属性的值可能需要调用String getName()方法读取,而写入属性值可能要需要调用void setName(String str)的方法。
  每个JavaBean属性通常都应该遵循简单的方法命名规则,这样应用程序构造器工具和最终用户才能找到JavaBean提供的属性,然后查询或修改属性值,对bean进行操作。JavaBean还可以对属性值的改变作出及时的反应。比如一个显示当前时间的JavaBean,如果改变时钟的时区属性,则时钟会立即重画,显示当前指定时区的时间。
  (2) 方法(method)
  JavaBean中的方法就是通常的Java方法,它可以从其他组件或在脚本环境中调用。默认情况下,所有bean的公有方法都可以被外部调用,但bean一般只会引出其公有方法的一个子集。
  由于JavaBean本身是Java对象,调用这个对象的方法是与其交互作用的唯一途径。JavaBean严格遵守面向对象的类设计逻辑,不让外部世界访问其任何字段(没有public字段)。这样,方法调用是接触Bean的唯一途径。
  但是和普通类不同的是,对有些Bean来说,采用调用实例方法的低级机制并不是操作和使用Bean的主要途径。公开Bean方法在Bean操作中降为辅助地位,因为两个高级Bean特性--属性和事件是与Bean交互作用的更好方式。
  因此Bean可以提供要让客户使用的public方法,但应当认识到,Bean设计人员希望看到绝大部分Bean的功能反映在属性和事件中,而不是在人工调用和各个方法中。
  (3) 事件(event)
  Bean与其他软件组件交流信息的主要方式是发送和接受事件。我们可以将bean的事件支持功能看作是集成电路中的输入输出引脚:工程师将引脚连接在一起组成系统,让组件进行通讯。有些引脚用于输入,有些引脚用于输出,相当于事件模型中的发送事件和接收事件。
  事件为JavaBean组件提供了一种发送通知给其他组件的方法。在AWT事件模型中,一个事件源可以注册事件监听器对象。当事件源检测到发生了某种事件时,它将调用事件监听器对象中的一个适当的事件处理方法来处理这个事件。
  由此可见,JavaBean确实也是普通的Java对象,只不过它遵循了一些特别的约定而已。
 
 
JavaBeans - Wikipedia https://en.wikipedia.org/wiki/JavaBeans

In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into a single object (the bean). They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods. The name "Bean" was given to encompass this standard, which aims to create reusable software components for Java.

It is a reusable software component written in Java that can be manipulated visually in an application builder tool.

Features[edit]

  • Introspection

Introspection is a process of analyzing a Bean to determine its capabilities. This is an essential feature of the Java Beans API because it allows another application such as a design tool, to obtain information about a component.

  • Properties

A property is a subset of a Bean's state. The values assigned to the properties determine the behavior and appearance of that component. It is set through setter method an can be obtained by getter method.

  • Customization

A customizer can provide a step-by-step guide through the process that must be followed to use the component in a specific context.

  • Events
  • Persistence

It is the ability to save the current state of a Bean, including the values of a Bean's properties and instance variables, to nonvolatile storage and to retrieve them at a later time.

  • Methods

Advantages

  • 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.

Disadvantages

  • A class with a zero-argument constructor is subject to being instantiated in an invalid state.[1] If such a class is instantiated manually by a developer (rather than automatically by some kind of framework), the developer might not realize that the class has been improperly instantiated. The compiler cannot detect such a problem, and even if it is documented, there is no guarantee that the developer will see the documentation.
  • JavaBeans are inherently mutable and so lack the advantages offered by immutable objects.[1]
  • Having to create getters for every property and setters for many, most, or all of them can lead to an immense quantity of boilerplate code.

内省

零参数构造器

Enterprise JavaBeans - Wikipedia https://en.wikipedia.org/wiki/Enterprise_JavaBeans

Enterprise JavaBeans (EJB) is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web container provides a runtime environment for web related software components, including computer securityJava servlet lifecycle managementtransaction processing, and other web services. The EJB specification is a subset of the Java EE specification.[1]

Specification

The EJB specification was originally developed in 1997 by IBM and later adopted by Sun Microsystems (EJB 1.0 and 1.1) in 1999[2] and enhanced under the Java Community Process as JSR 19 (EJB 2.0), JSR 153 (EJB 2.1), JSR 220 (EJB 3.0), JSR 318 (EJB 3.1) and JSR 345 (EJB 3.2).

The EJB specification intends to provide a standard way to implement the server-side (also called "back-end") 'business' software typically found in enterprise applications (as opposed to 'front-end' user interface software). Such machine code addresses the same types of problems, and solutions to these problems are often repeatedly re-implemented by programmers. Enterprise JavaBeans is intended to handle such common concerns as persistencetransactional integrity, and security in a standard way, leaving programmers free to concentrate on the particular parts of the enterprise software at hand.

原文地址:https://www.cnblogs.com/rsapaper/p/9950432.html