EJB Interview Questions

This article brings you the basic comprehensive concepts of EJB. And mainly, it focuses on all the questions that are frequently asked in job interviews. It includes definitions, components, how to deploy servers, and many important topics covered in this blog. So, let's get started!

Enterprise Java Beans (EJB) is a developing framework for building highly scalable and dependable enterprise applications that run on J2EE application servers like Web Logic and JBOSS. Our Top EJB Interview Questions and Answers will provide you with a comprehensive knowledge of EJB concepts that will help you build and deploy a business application.

So here are the EJB Interview Questions that are classified as follows:

  1. Freshers
  2. Intermediate
  3. Experienced

Frequently Asked EJB Interview Questions:

  1. What are the advantages of EJB?
  2. What are the various components of Message-driven beans?
  3. What are the important elements of EJB?
  4. What is a remote client view?
  5. What Is a Deployment Descriptor?
  6. What does ACID mean in the context of transaction management?
  7. What is Callback in EJB?
  8. Is it possible to have threading in an EJB application?
  9. What are the callbacks annotations for entity beans?
  10. Is Decorator a Design Pattern in Ejb?

EJB Interview Questions and Answers for Freshers:

1. What is meant by EJB?

EJB refers to Enterprise Java Beans. It is a server-side application that is used to build corporate software modules. It connects distributed and business-level applications to a container, or application server. EJB is a critical component of the J2EE framework. Enterprise-level applications can use the J2EE platform's component-based architecture to deliver distributed, multi-tiered, and highly transactional features.

EJB provides a framework for developing and deploying component-based enterprise applications with excellent reliability, scalability, and performance. Any application server that complies with the J2EE 1.3 standard specification can host an EJB application. Containers offer transaction management and security, making it easier for developers and users to deal with them. Concentrating on business concepts is simple for them.

2. What are the advantages of EJB?

Here are the few benefits of EJB:

  • Large-scale enterprise-level application development is simplified.
  • The majority of system-level functions, including transaction management, persistence mechanisms, exception handling, logging, load balancing, and so on, are provided by the Application Server/ EJB container. The developer must concentrate solely on the application's business logic.
  • The life cycle of EJB instances is managed by the EJB container, so developers do not have to contend about when to create/delete ejb items.
Want to enhance your skills in dealing with the world's best Programming & Frameworks Courses , enroll in our Core Java Training Online

3. Explain the architecture of EJB?

The following image explains the EJB Architecture:

  • Application Server: This webserver is the architecture's outermost layer, and it houses the container. It provides the essential environment for running the beans-based applications. Some of the most popular application servers on the market include JBoss, Wildfly, Web-logic, Web-sphere, Tomcat and Glass-finish.

Application servers' major functions are to: a. manage interfaces, b. execute processes, c. connect to databases, and d. manage other resources.

  • Container: The container is the EJB structure's second functional unit, and it contains the following integrated services to the enterprise beans it houses.
    • Transactional services, for example Object registration, remote interface assignment, and instance purging
    • Monitoring the objects' activity and managing distributed components
    • Security services and resource pooling
    • Manages bean lifecycles and concurrency
    • Assist the developer in concentrating on the business logic
  • Beans: Enterprise java beans are similar to plain old java objects (POJO) and are assigned to the container. Beans contain business logic for building large-scale, secure commercial systems.

Architecture of EJB

4. What are the various types of Enterprise Java Beans(EJB) components?

An enterprise bean is a non-visual element of a transaction-oriented, distributed, and corporate application is an enterprise bean. EJB containers and EJB servers are commonly used to deploy enterprise beans.

Session beans, message-driven, and entity beans are the three basic forms of enterprise beans.

  • Session Beans: Non-persistent enterprise beans are known as session beans. They can have a state or not. A stateful session bean serves as the representative of a single client and keeps a conversational state (client-specific session information) across numerous method calls and transactions. In the context of a single client/server session, it exists. In contrast, a stateless session bean maintains no conversational state. The container pools stateless session beans to accommodate many requests from various clients.
  • Message-driven beans: Enterprise beans that store and transmit JMS messages are known as message-driven beans. Message-driven beans, neither entity nor session beans, have no interfaces. They can only be retrieved through texting and do not keep a discussion going. Message-driven beans enable asynchronous communication between the listener and the queue while also separating message processing from business logic.
  • Entity Beans: Entity beans are enterprise beans that store persistent data in a variety of persistent data stores. Each entity bean has a unique identification number. Bean-managed persistence (BMP) entity beans are entity beans that handle their persistence. Container-managed Persistence (CMP) entity beans are entity beans that transfer their persistence to their EJB container.

5. What are the various components of Message-driven beans?

There are two components in Message-driven Beans:

  • Stateless Session Bean: It is only present for a brief time. It's utilized when there's no need to be concerned about a client's condition. The Stateless session bean is a wonderful illustration of credit card validation.
  • Stateful Session Bean: It has a distinct advantage over other beams in that it can be deployed on the web, whereas others cannot. It is utilized to keep the client's conversation going. Before going into an inactive state, it saves the instance of communication in a location similar to a hard disk. When the same client sends a request to return to its original location (main memory). Stateful transactions and reservations are two instances of online transactions.

6. What are the differences between Stateless and Stateful Session Bean?

The following are the distinctions between stateful and stateless session beans:

  • To process each client request, the EJB container constructs a new stateful session bean.
  • EJB Container, on the other hand, produces a pool of stateless bean objects and uses them to handle client requests.
  • The stateful session bean is destroyed when the request scope expires, while the stateless bean stays operational.
  • A stateful session bean is a form of enterprise bean that keeps track of the client's conversational state. As the name implies, a stateful session bean preserves related client state in its instance variables. In stateless session beans, object values are not guaranteed to be consistent between lookups/method calls due to the pool of stateless session beans.

 MindMajix YouTube Channel

7. What are the important elements of EJB?

  • Entity representation of the database of the data persistence maintenance.
  • The Entity Manager serves as an interface. It is used to execute a variety of tasks such as adding, deleting, updating, and finding. It's also where the queries are handled.
  • The persistence unit is a collection of all entity classes that are used to maintain persistence.
  • Data source as the name implies this property is related to data storage.

 

8. Explain about Session facade?

As a wrapper class, the design pattern employed is a session facade. It is crucial for the implementation of business applications. It improves the system's performance by reducing network calls. Although it is implemented as a high-level component (Session EJB), it is made up of interactions between low-level components (Entity EJB). It also lets the client interact with bean elements.

9. Explain about the attributes of transactions in EJB?

  • Required: When the required attribution is attached to the transaction, no new transaction is created.
  • Requires News: When this attribute is linked to the transaction, it always requires the addition of a new transaction.
  • Not supported: If this attribute is attached to a method, the method is no longer part of the transaction.
  • Supported: It is supported in the conditional case, which is dependent on the caller component. The method acts as a necessary attribute if the calling component is tied to a transaction. The method functions as NOT SUPPORTED if the caller component is not linked to the transaction.
  • Mandatory: When a method is linked to this attribute, it is always called from the transaction context of the calling element.
  • Never: When a method is linked to this attribute, it is always called from the transaction context of the calling element.

10. Explain about EJB Server?

An enterprise bean server is a high-level procedure or application that offers a run-time environment for server applications that employ enterprise beans. A JNDI-accessible naming service, management and coordination of resource allocation to client applications, access to system resources, and a transaction service are all provided by an EJB server. An application server or database, for example, may provide an EJB server.

11. Explain about EJB Container?

An EJB container is a run-time framework that maintains one or more enterprise beans. The EJB container organizes distributed transactions, maintains enterprise bean object life cycles, and provides object security. In general, an EJB server provides each EJB container, which contains a collection of enterprise beans that operate on the server.

EJB Interview Questions and Answers for Intermediate:

1. What is a remote client view?

Only EJB 2.0 supports the remote client view specification. An enterprise bean's remote client view is location agnostic. A client operating in the same JVM as a bean object allows users to access the bean using the same API as a client functioning in a distinct JVM on the same or distinctive computer.

  • The remote interface defines the remote business model that a client can use to interact with an enterprise bean.
  • The remote home interfaces specify how distant clients locate, create, and remove objects of business bean classes.

2. What is Local client view?

Only EJB 2.0 supports the local client view specification. The local client view of a bean, unlike the remote client view, is location dependent. Both the local client and the business bean that supplies the local client view must be running in the same JVM. As a result, the local client view lacks the location transparency afforded by the remote client view. Lightweight access from enterprise beans that are local clients is supported through local functionalities and local home interfaces. Clients can be tightly coupled with session and entity beans, providing access without the overhead related to remote method calls.

3. What Is a Deployment Descriptor?

A deployment descriptor is an XML file included in an EJB JAR or EAR file along with the enterprise beans. It holds metadata on the enterprise beans' contents and structure, as well as security and transaction information for the EJB environment at runtime.

4. What is meant by Lazy Loading?

When loading plug-ins, heavy-weight applications take a long time to load. The plug-ins that are required at that time are imported and configured using the lazy loading approach. This improves performance because only the plug-ins that are used are loaded. This also ensures application efficiency and reduces application startup time. This is how applications like Eclipse work. To put it another way, lazy loading aims to only allocate RAM when it is completely essential.

5. What is meant by EJB Ql?

Enterprise Java Beans-Query Language is what EJB QL stands for. The EJB 2.0 standard added it. EJBs and dependent objects established by container-managed persistence allow users to navigate through a pipeline of EJBs. Persistence refers to a bean's capacity to save its existing state. EJB QL can be used in a variety of containers and persistent managers.

  • Finder Methods: These are declared in an entity bean's home interface and return entity objects.
  • Selection Methods: Clients are not allowed to see these methods. Bean providers, on the other hand, employ these to choose persistence variables or entity objects associated with the entity bean on which the query is specified.

6. Explain the concepts of connection pooling features of EJB Container?

  • It is an exceptional feature of the container since it improves the application's performance.
  • Clients benefit greatly from connection pooling because they do not need to connect to the database every time. The connection pool already contains many of the functions.
  • When a client request is made, an instance is selected from the connection pool, and when the user's task is completed, the instance is returned to the connection pool.
  • The app server has a limited number of connections available. When this limit is exceeded, a pre-determined amount of the connection pool is increased. When the demand for connections returns to normal, the excess connection pools are removed.

7. What is meant by transactions and various methods to manage it?

A transaction is a group of people who either work full-time or part-time to integrate and manage data. Acid transactions have specific qualities such as atomicity, consistency, integrity, and durability. The commitment to effective implementation over unsuccessful performance is the completed transaction.

There are two approaches to managing transactions:

  • Declarative Transaction Management
  • Programmatic Transaction Management
Want to know more about Core Java  - Check Java Tutorial

8. What does ACID mean in the context of transaction management?

  • Atomic: If any working part fails in this circumstance, the entire work is considered destroyed. Only truly accomplished people are valued.
  • Consistent: This term denotes that the transaction management system must stay consistent.
  • Isolated: means that the transaction is executed independently of other transactions.
  • Durable: Means that if any by-case transaction has been completed, it must have survived a system failure.

ACID in context of transaction management

9. What is Callback in EJB?

A callback is a technique for intercepting the entire process of an enterprise bean. Callbacks for which callback controller methods are to be produced are described in the EJB 3.0 specification. These callbacks are invoked by the EJB Container. Callback methods can be defined in the EJB class itself or a different category. Many identifiers for callbacks are available in EJB 3.0.

EJB Interview Questions and Answers for Experienced:

1. To explain the timer service in EJB?

The Timer Service is a technique for creating scheduled applications. For instance, salary slips are generated on the first of each month. The Timeout annotation in the EJB 3.0 specification aids in implementing the EJB function in a stateless or message-driven bean. The method annotated with @Timeout is called by the EJB Container.

EJB Timer Service is an EJB container service that allows you to create timers and schedule callbacks when they expire.

2. Is it possible to have threading in an EJB application?

Threading is not possible with EJB since the container manages and controls the processing. If threading is permitted, the container will be impacted. As previously said, EJB is intended to reduce the developer's workload and allow them to focus solely on business logic. Because EJB isn't designed to manage the system or implementation, the thread is managed by the container.

3. What is the procedure and creation of Stateless EJB?

The process of creating a stateless EJB is straightforward:

  • First and foremost, you must create a local interface.
  • This interface must be utilized by the client programme once it is completed.
  • After that, it must recognise the EJB's environment. Use @Local annotation if the environment is the same, and @Remote annotation if the environment is different.
  • Create a stateful session bean after that.
  • Finally, to infer a stateful bean, use the @Stateful annotation.

4. What are the callbacks annotations for entity beans?

The following is a list of entity bean callback annotations:

  • @PrePersist: When the entity is created in the database, this method is invoked.
  • @PostPersist: Called after the entity has been created in the database.
  • @PreRemove-When an entity is deleted from the database, this method is invoked.
  • @PostRemove: When an entity is deleted from the database, this method is invoked.
  • @PreUpdate: When the database entity is updated, this function is called.
  • @PostLoad: This method is called when the entity in the database has to be updated.

5. What is EJB Containers' procedure for handling exceptions?

  • On the occurrence of an application exception: EJB returns the exception to the client because it was intercepted. The EJBContext method (). setRollBackOnly () determines whether or not the transaction should be rolled back.
  • On the occurrence of a system exception: EJB intercepts the transaction, rolls it back, and then starts the cleanup operations. Before communicating the exception to the client, it changes it to RemoteException.

6. What is the difference between SessionContext and EntityContext?

Because EnterpriseBeans are contained in a regulated container, the container is allowed to call the methods of your EJB components whenever it wants. The EJBContext Object contains information such as the current condition of the bean and the security credentials of the user currently accessing the bean in one object. Beans can use contexts to conduct callbacks and change their current status. The EJB context for session beans is the session context. The EJB context for entity beans is the entity context. The EJB context for message-driven beans is called the message-driven context.

7. Is Decorator a Design Pattern in Ejb?

No. The decorator design pattern displays very low-level dynamic polymorphism for a distinct and solitary entity (object of the class), but not for a class. It's the item that lets you add unique functionality to a single, pointed object while leaving others alone. It has a lot of parallels to aspectJ items, but not to EJB stuff.

8. What do you understand by annotation in EJB to do the database entity relationship with examples?

The EJB provides some annotations, which are listed below.

  • OneToOne: An object has a one-to-one relationship. A person might, for example, use a credit card to purchase a television.
  • OneToMany: An item with several connections. A cat, for example, has several kittens.
  • ManyToOne: An object has multiple connections to one another. For example, a large number of passengers share a single train to reach their destination.
  • ManyToMany: An object with a large number of connections. For instance, a serial can have various models, and a model can work in multiple serials.

9. Differentiate Ear, Jar, and War files?

Modules are packaged as EAR, JAR, and WAR files dependent on their functionality.

  • JAR files (.jar): JAR files are used to package modules that contain EJB deployment descriptors and EJB class files.
  • WAR Files (.war): JAR files are used to package web modules that contain supporting files, HTML, JSP files,  Java class files, and  GIF files.
  • EAR Files (.ear): JAR files are encapsulated as '.jar' and '.war' files. The Enterprise archive is referred to as 'Ear.' The application server receives these files.

10. Differentiate an interface and an Abstract?

The method bodies of an abstract class might contain code, which is not permitted in an interface. You must acquire your class from abstract classes, and Java does not enable multiple inheritances. In your class, however, you can implement numerous interfaces.

11. Explain about Singleton Session Beans?

A singleton session bean has only one instance per application, and that instance exists throughout the application's lifespan. Its operation is identical to that of stateless session beans. The sole distinction is that each application has only one singleton session bean, whereas the stateless session bean uses a pool of beans.

Conclusion:

These EJB Interview Questions can help you estimate the types of questions you'll be asked during your EJB deployer job interview. I hope that these EJB interview questions and answers will assist you in accomplishing your job interview and securing your ideal job.

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Core Java TrainingNov 19 to Dec 04View Details
Core Java TrainingNov 23 to Dec 08View Details
Core Java TrainingNov 26 to Dec 11View Details
Core Java TrainingNov 30 to Dec 15View Details
Last updated: 08 Jan 2024
About Author

 

Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less
  1. Share:
Java Articles