Difference between Javabean and EJB [duplicate] Difference between Javabean and EJB [duplicate] java java

Difference between Javabean and EJB [duplicate]


Java bean is just a set of conventions. EJB is a standard for J2EE business components.

Specifically a Java bean:

  • has a public default constructor;
  • readable property methods precedes with "get";
  • writable property methods precedes with "set"; and
  • is Serializable.

For example, a Java bean with a property of "margin" would minimally look like this:

public class MyBean implements Serializable {  private int margin;  public MyBean() { }  public int getMargin() { return margin; }  public void setMargin(int margin) { this.margin = margin; }}

EJB, despite the name, is almost completely unrelated.


Take a look at this article - JavaBeans vs Enterprise JavaBeans

SUMMARY:

JB

JavaBeans takes a low-level approach to developing reusable software components that can be used for building different types of Java applications (applets, stand-alone apps, etc.) in any area.

EJB

Enterprise JavaBeans takes a high-level approach to building distributed systems. It frees the application developer to concentrate on programming only the business logic while removing the need to write all the "plumbing" code that's required in any enterprise application.


  1. JavaBeans may be visible or nonvisible at runtime. Forexample, the visual GUI component may be a button, listbox, graphic or a chart.

    An EJB is a nonvisual, remote object.

  2. JavaBeans are intended to be local to a single processand are primarly intended to run on the client side. Althoughone can develop server-side JavaBeans, it is far easier todevelop them using the EJB specification instead.

    EJB's are remotely executable components or businessobjects that can be deployed only on the server.

  3. JavaBeans is a component technology to create genericJava components that can be composed together into appletsand applications.

    Even though EJB is a component technology, it neitherbuilds upon nor extends the original JavaBean specification.

  4. JavaBeans have an external interface called the propertiesinterface, which allows a builder tool to interpret thefunctionality of the bean.

    EJBs have a deployment descriptor that describes itsfunctionality to an external builder tool or IDE.

  5. JavaBeans may have BeanInfo classes, property editors orcustomizers.

    EJB's have no concept of BeanInfo classes, propertyeditors or customizers and provide no additional informationother than that described in the deployment descriptor.

  6. JavaBeans are not typed.

    EJBs are of two types - session beans and entity beans.

  7. No explicit support exists for transactions in JavaBeans.

    EJB's may be transactional and the EJB servers providetransactional support.

  8. Component bridges are available for JavaBeans. For example, aJavaBean can also be deployed as an Activex control.

    An EJB cannot be deployed as an ActiveX control becauseActiveX controls are intended to run at the desktop andEJB's are server side components. However CORBA-IIOPcompatibility via the EJB-to-CORBA mapping is defined by theOMG.