EJB Interview Questions

These are some questions for the EJB interviews. Although you may have a good knowledge of EJB, you must revise the topics through answering questions. As EJB interviews are tough because the interviewers try to find the most talented developers in this field. So, to help you, we share some important questions that may help you in your interviews.

#1 What is JAR, WAR, and EAR?

  • JAR contains all EJB class.
  • WAR contains servlets, gif, HTML, applets, classes and many more.
  • EAR contains both WAR and JAR files.

#2 What is the procedure for the presentation of EJP persistence mechanism?

  • First, you need to build a database table
  • After that, build entity classes for the table
  • When it is done, you need to build data source and persistent unit
  • Then, build a stateless EJB
  • And then, Update it
  • At last, Console based application enters the stateless EJB.

#3 What do you mean by timer service and where it is used?

Timer service is a method to construct a scheduled program. @Timeout is used in EJB 3.0 to maintain the EJB services in the beams such as stateless session beam and Message Driven beam too. Example of timer service is the generation of salary slips on any particular date of the month.

#4 What is the procedure for the creation of stateless EJB?

Creation of stateless EJB is done in simple steps:

  • First of all, you need to build a local interface
  • When it is done, the client application has to be used this interface.
  • And then, it needs to recognize the environment of the EJB. If the environment is same then use @Local annotation and if it different then use @Remote annotation
  • After that build a stateful session bean.
  • At last use @Stateful annotation to imply a stateful bean.

#5 What is EJB?

EJB stands for Enterprise java bean is a server-side software that is used to construct the module of enterprise software. It works on the container or we can say application server to scattered and business level application. Container plays a supporting function to transaction management and security that helps the developers and users to work on it easily. It is simple for them to concentrate on business logic.

#6 Explain the concept of EJB QL?

The query language is used to provide the navigation with the help of network and consists beans. Container-managed persistence determined the enterprise beans. EJB QL emerged in EJB 2.0. It is motile through the persistence manager that helps to determine methods of the finder. It helps the two kinds of the finder system. EJB QL is not good than SQL as it works as an abstract schema.

  • Finder method: It allows the client to use the result of the EJB QL query.
  • Select method: In this, clients are able to describe the full query or just the part of it (WHERE clause).

#7 What are the callback annotations for entity bean?

Here is the list of callback annotation for an entity bean:

  • @PrePersist -This method is summoned when the entity is built in the database.
  • @PostPersist - This method is summoned after the entity is built in the database.
  • @PreRemove-This method is summoned when the entity is deleted from the database.
  • @PostRemove-This method is summoned when the entity is deleted from the database.
  • @PreUpdate-This method is summoned when the entity is updated in the database.
  • @PostLoad-This method is summoned when the entity is to be updated in the database.

#8 What is the procedure of EJB container to handle exceptions?

On Occurrence of Application exception: EJB return the exception to client as it is intercepted. The method EJBContext().setRollBackOnly() specify that whether the transaction it should be rolled or not.

On Occurrence of System Exception: Here EJB first intercepts the transaction, rollback it and then initiate the clean-up tasks. It converts the exception into RemoteException before sending to the client.

#9 Explain the concept of connection pooling feature of EJB container?

  • It is the extraordinary feature of Container as It increases the performance of the application.
  • The clients get a lot of help from this connection pooling as they don't need every time connection with the database. Many of the functions are already given in the connection pool.
  • An instance is picked from the connection pool when an instance is received for the client or turned this instance to the connection pool when the user completes his/her work.
  • The connections are available in a limited amount in the app server. Exceeding this limit, a pre-restrained amount of connection pool enhances. And when the need of connection goes normal, then these extra connection pools are eliminated.

#10 What are the callback annotations for the stateless bean?

Below are the callback annotations for the stateless bean:

  • @PostConstruct - method is invoked when a bean is created for the first time.
  • @PreDestroy – When a bean is destroyed or displaced from the bean pool, this method is invoked.

#11 What are the various types of Entity beam?

Entity beam is divided into two types: -

  1. CMP Entity bean: It is defined as Container Managed Persistence. It is the complex type of bean and very effective for the developer as in this, developers don't need to take care of the databases and transactions.
  2. BMP Entity bean: BMP stands for Bean Managed Persistence. In this, develop has the duty or responsibility of all the database.

#12 Is it possible to have threading in EJB?

It is not possible to have threading in EJB because Container maintains and controls the processing in EJB. And if threading is allowed in this, the container will be affected. As it is discussed earlier, EJB is designed to Lower the work on the developer and make them easier to just focus on business logic. EJB is not built to control the system or implementation works so container itself manage the thread.

#13 What are the various types of Entrepreneur java bean?

The various types of EJB are: -

  • Entity Bean: The object that is planned with the database is referred to an entity bean. It is used to execute OR entity Relational planning with the database. All the tables of RDBMS are recognized by the entity bean. Every instance in the table has described a row.
  • Session bean: Session bean is another type of beam which is created for some period of time. It is designed for a single server or client and also created by the client. It is not a permanent type beam, therefore, there is a high risk of failure issue and cannot be recoverable.
  • MDB: It stands for Message Driven Beans and it is the last beam type. It is invoked when any type of message comes from the JMS and Topic. It is created to work as a listener.

#14 How does EJB invocation happens?

The steps that are followed:

  • Home Object Interface creates a new EJB object
  • Gives back EJB object reference to the client
  • With the use of EJB object reference invokes business methods
  • Delegate requests to the bean.

#15 Elucidate callback in EJB?

Life-cycle of the enterprise can be stooped with the help of Callback. The Callback method is needed to design as in the case of EJB 3.0 it has some specified callbacks. EJB 3.0 gives too many explanations regarding the callbacks.

Ask a Question