Introduction To EJB (Enterprise Java Beans)

The Java Enterprise Edition architecture is based on Component-Container architecture. The container contains various components and supports the component in performing its functionality, by providing them an execution environment.

Java EE has 3 different types of components - EJB Components (Session bean, Message-driven bean), Web Components (Servlet, JSP, JSF) and Client Components (Application client component, Applet). The EJB components are contained by the EJB container which is a part of Java EE Application Server.

Let us understand the EJB components here.

What is EJB?

  • EJB stands for "Enterprise Java Beans". 
  • EJB is a development architecture which allows us to make component based secured, scalable and robust applications. EJB enables the development of reusable business logic components.
Types of Enterprise Java Beans
  1.  Session beans
  2.  Message-driven beans
A. Session Beans
  • Session beans are Java beans which encapsulate the business logic in a centralized and reusable manner such that it can be used by a number of clients.
  • Session beans are plain old Java objects which function as server-side extension performing business logic.
  • As session beans are server-side extensions, they can be accessed by various types of clients, like another enterprise beans, a web component such as a Servlet, a plain Java class or a web service.
  • There are 2 types of client access models for session beans - Local client access and Remote client access.
  • Local clients are components residing in the same enterprise application while remote clients are components executing in a remote JVM.
There are 3 types of Session beans -
  1. Stateless Session Beans (SLSB) - Provide user generic business processing and are not tied to a specific client.
  2. Stateful Session Beans (SFSB) - Provide user specific business processing and are tied to a specific client.
  3. Singleton Session Beans (SSB) - Provide shared data access to client and components within an application and are instantiated only once per application.
B. Message-driven Beans
  • Message-driven beans are EJB beans which are driven with the help of messages.
  • There are 2 types of Message-driven beans -

    • JMS (Java Messaging System) Message-driven beans 
    • Non-JMS Message-driven beans
Ebook Download
View all
Learn
View all