Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Javabean and EJB [duplicate]

Just a simple question from a relative Java newbie:

what is the difference between a JavaBean and an EJB?

like image 273
LRE Avatar asked Sep 01 '09 10:09

LRE


People also ask

What is the difference between JavaBeans and EJB?

A JavaBean is a Java class that encapsulates multiple objects and conforms to certain conventions. JavaBeans are used mainly for client-side development. An enterprise bean (EJB) is a Java class imbued with specific server-side capabilities. Enterprise beans are used in large-scale business applications and systems.

What is the difference between EJB and POJO?

EJB3 entities are plain POJOs. Actually they represent the exact same concept as the Hibernate persistent entities. Their mappings are defined through JDK 5.0 annotations (an XML descriptor syntax for overriding is defined in the EJB3 specification).

What is the purpose of a JavaBean?

JavaBeans is a portable, platform-independent model written in Java Programming Language. Its components are referred to as beans. In simple terms, JavaBeans are classes which encapsulate several objects into a single object. It helps in accessing these object from multiple places.

What are the different types of EJBs?

There are three types of EJBs: session beans, entity beans, and message-driven beans.


3 Answers

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.

like image 123
cletus Avatar answered Oct 02 '22 12:10

cletus


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.

like image 36
KV Prajapati Avatar answered Oct 02 '22 12:10

KV Prajapati


  1. JavaBeans may be visible or nonvisible at runtime. For example, the visual GUI component may be a button, list box, graphic or a chart.

    An EJB is a nonvisual, remote object.

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

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

  3. JavaBeans is a component technology to create generic Java components that can be composed together into applets and applications.

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

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

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

  5. JavaBeans may have BeanInfo classes, property editors or customizers.

    EJB's have no concept of BeanInfo classes, property editors or customizers and provide no additional information other 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 provide transactional support.

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

    An EJB cannot be deployed as an ActiveX control because ActiveX controls are intended to run at the desktop and EJB's are server side components. However CORBA-IIOP compatibility via the EJB-to-CORBA mapping is defined by the OMG.

like image 45
Charu Jain Avatar answered Oct 02 '22 11:10

Charu Jain