Diff B/W Java Bean and Ejb: Mybean Serializable
Diff B/W Java Bean and Ejb: Mybean Serializable
A JavaBean is just a plain old Java object that conforms to certain conventions including the
use of accessor functions (getFoo/setFoo) for member access, provision of a default
constructor and a few other things like that.
JavaBeans were originally mostly intended to be used in builder tools by providing a known
interface which could be looked for through introspection in the tools. They quickly turned
into what amounts to a religion, however.
Enterprise JavaBeans are intended to provide encapsulated business logic for enterprise
applications within a general container that provided things like session management,
security, resource pooling, etc. as services thus allowing the business logic to be (relatively)
untainted by these cross-cutting concerns. (Whether or not they accomplished this is a
matter that is up for debate, given how difficult they were to use at first. More recent
versions of the specification have made this easier, however. Legacy apps, though, are still
a pain and sadly likely the majority of the EJBs you're likely to encounter.)
Java bean is just a set of conventions. EJB is a standard for J2EE business components.
public MyBean() { }
public int getMargin() { return margin; }
public void setMargin(int margin) { this.margin = margin; }
}
EJB, despite the name, is almost completely unrelated.
Java Beans :
- Java beans are reusable components that can be used for customized user objects.
- Java beans adhere to two methods known as setter and getter methods and one public
constructor.
- For example: an employee object can be used to set (setter method) and get (getter method)
employee details which are a customized object.
- EJB are reusable components that are developed to comply with enterprise specification
adhering to setter and getter methods and one public constructor.
JavaBeans :
- JavaBeans are intended to be local to a single process and are primarily 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.
- JavaBeans have an external interface called the properties interface, which allows a
builder tool to interpret the functionality of the bean.
EJB :
- EJB's are remotely executable components or business objects that can be deployed
only on the server.
- Even though EJB is a component technology, it neither builds upon nor extends the
original JavaBean specification.
- EJB's may be transactional and the EJB servers provide the transactional support.