views:

409

answers:

3

Just a simple question from a relative Java newbie:

what is the difference between a JavaBean and an EJB?

+3  A: 

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 propertiy methods prepended with "get";
  • writable propertty methods prepended 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.

cletus
There's a bit more to JavaBeans (you can have a BeanInfo class for example), but that's the part of JavaBeans that's widely used.
Joachim Sauer
Can you explain what an EJB is in addition to what it is not?
allyourcode
A: 

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.

adatapost