Just a simple question from a relative Java newbie:
what is the difference between a JavaBean and an EJB?
Java bean is just a set of conventions. EJB is a standard for J2EE business components.
Specifically a Java bean:
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.
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.
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.
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.
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.
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.
JavaBeans are not typed.
EJBs are of two types - session beans and entity beans.
No explicit support exists for transactions in JavaBeans.
EJB's may be transactional and the EJB servers provide transactional support.
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.
I found it little cumbersome to understand from the accepted answer so googled few more links and got below answer.
Enterprise JavaBeans (EJB) 3.1 these are J2EE specifications which instructs server (application server) to deploy a piece of code in EJB Container.
EJB technology is the server-side component architecture for the development and deployment of component-based business applications. EJB technology enables rapid and simplified development of distributed, transactional, secure, and portable applications based on Java EE 6 technology.
In simple language: If you create an EJB and deploy it on server, it can be called remotely (using some technique, i.e. JNDI lookup using RMI) or locally (i.e. with in an application).
On the other hand, Java beans, is a simple plain Java class with getters and setters and that class is serialized, below is the example:
public class MyBean implements java.io.Serializable
{
protected int theValue;
public MyBean()
{
}
public void setMyValue(int newValue)
{
theValue = newValue;
}
public int getMyValue()
{
return theValue;
}
}
So, it means there is no comparison between EJB and Java Beans, both are totally different concept.