Enterprise JavaBeans (EJB)
Enterprise Java Beans (EJB)

In this course, we'll cover the basics of Enterprise JavaBeans (EJB) before moving on to explore the various components of the service. We'll round off the course with some example exam questions on business tier technologies.

Learning Objectives

  • Learn the basics of EJB
  • Learn about the various components of EJB:
    • Stateless session and stateful session beans
    • Singleton session beans
    • Message-driven beans

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java Enterprise Edition.


Basic knowledge of Java programming.


Hello dear friends. In this video, we will start to examine EJB, let's begin. Enterprise Java Beans also known as EJB is one of the several Java APIs for standard manufacturer of enterprise software. EJB is a server-side software element that summarizes business logic of an application. Enterprise Java Beans web repository yields a runtime domain for web related software elements including computer reliability, Java servlet lifecycle management, transaction procedure, and other web services. The EJB enumeration is a subset of the Java EE enumeration. So, what are the advantages of EJB?

The EJB Enumeration was originally developed by IBM in 1997 and later adopted by Sun Microsystems in 1999 and enhanced under the Java community process. For several reasons, enterprise beans simplify the development of large distributed applications. First, because the EJB container provides system level services to enterprise beans, the bean developer can concentrate on solving business problems.

The EJB container rather than the bean developer is responsible for system level services such as transaction management and security authorization. Second, because the beans rather than the clients contain the applications business logic, the client developer can focus on the presentation of the client. The client developer does not have to code the routines that implement business rules or access databases. As a result, the clients are thinner, a benefit that is particularly important for clients that run on small devices. Third, because enterprise beans are portable components, the application assembler can build new applications from existing beans provided that they use the standard APIs, these applications can run on any compliant Java EE server. Of course, there are some disadvantages of EJB like: EJB requires an application server and only a Java client. For another language client you need to go for web service. EJB applications are too complex to understand and develop. EJB performs lifecycle management, security, transaction management, and object pooling.

To run EJB application, you need an application server such as JBoss, GlassFish, WebLogic, WebSphere, etc. As you are aware, we have already installed the GlassFish server on our clips. If your application needs remote access to be scalable or encapsulated business logic, you can choose using EJB in your application. To develop an enterprise bean, you need some file types like: enterprise bean class, business interfaces, and helper classes. Enterprise bean class implements the business methods of the enterprise bean and any lifecycle callback methods. Business interface defines the business methods implemented by the enterprise bean class. A business interface is not required if the enterprise bean exposes a local no interface view. Helper classes are the other classes needed by the enterprise bean class, such as exception and utility classes. You have to package the programming artifacts either into an EJB jar file or within a wall module. The image shows us the EJB jar structure. An EJB jar file is portable and can be used for various applications. To assemble a Java EE application, package one or more modules such as EJB jar files into an EAR file, the archive file that holds the application.

When deploying the EAR file that contains the enterprise beans EJB jar file, you also deploy the enterprise bean to the GlassFish server. You can also deploy an EJB jar that is not contained in an EAR file. Before looking at the various types of EJB, I want to discuss the enterprise bean naming conventions that we will use in a few of the following code snippets. I want to talk about an employee EJB. So, I will show examples with employee. For an employee EJB, we have to define EJB name with name and EJB keyword like employee EJB. For EJB jar, we will define our name as employee jar, like EJB name. For an enterprise bean class name, we will use bean keyword, so our name will be employee bean. For home interface, we will use home keyword and our name will be employee home. For remote interface, we don't need any keyword, we will only use interface name, so our name will be employee. For local home interface, our name must be local employee home. And the last one is local interface, we need local keyword in front of the name, so our name will be local employee. The name conventions are very important for programming. Therefore, we need to pay attention to these naming conventions.

Now let's go on with enterprise beans types. There are three kinds of enterprise beans: session, message-driven, and entity. Session bean contains business logic that can be invoked by local, remote, or web service client. Like session bean, message driven bean contains the business logic but it is invoked by parsing message. Entity bean encapsulates the state that can be persisted in the database. It is now deprecated and is replaced with JPA. We will examine all of them one by one in the following videos. That's all I have to say about EJB definition. In the next video, we will examine the EJB container. See you in the next video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics