EJB Interview Questions

  1. Which services are provided to EJB components by the EJB container?
  2. What is the procedure of EJB container to handle exceptions?
  3. What is JAR, WAR, and EAR?
  4. Is EJB be called from another EJB? If yes then how?
  5. How does EJB invocation happens?
  6. What is the procedure for the presentation of EJP persistence mechanism?
  7. What are the callback annotations for entity bean?
  8. What is the meaning of ACID in the connection of transaction management?
  9. What do you understand by annotation in EJB to do the database entity relationships/mappings with examples?
  10. What is the procedure for the creation of stateless EJB?
  11. Explain the concept of EJB QL?
  12. What are the attributes of transaction in EJB?
  13. Explain transaction and various methods to manage it?
  14. What do you understand by Session facade?
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.

Download EJB Interview Questions PDF

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.

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

Yes, an EJB can be called from another EJB. The JNDI is used for this process which also used for locating the Home Interface and to receive instances.

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.
  • 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.

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.
  • Atomic - In this case, if any working part fails then the whole work is considered as destroyed. It values only fully successful.
  • Consistent -It represents that the transaction management must remain in a consistent state
  • Isolated-It states that the execution of the transaction is independent of the other transactions.
  • Durable -It means if any by case transaction has been executed then it must have survived system failure.

Here are some annotations that are provided by the EJB.

  • OneToOne - The object that has one to one connection. For example, a person goes to buy a TV using a credit card.
  • OneToMany - The object that has one to many connections. For example, a cat has many kittens.
  • ManyToOne - The object that has many to one connection. For examples, A lot of passengers has a single train to visit destiny.
  • ManyToMany - The object that has many to many connections. For examples, A serial has many models and a model works in many serials.

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.

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).

Here are some transaction attributes

  1. Required: No new transaction is created when the required attributed is linked to the transaction.
  2. Requires New: There is always present the addition of a new transaction when this attributed is linked to the transaction.
  3. Not Supported: If the method is linked to this attribute then the method does not remain part of the transaction
  4. Supported: It acts in the conditional case that depends on the calling component. If the calling element is linked with transaction then the method act as a required attribute. If the calling component is not linked with the transaction then the method acts as NOT SUPPORTED.
  5. Mandatory: The method is always called from the calling element transaction context when the method is linked to this attribute.
  6. Never: The method is never called from the calling element transaction context when the method is linked to this attribute.

Support is the default transaction value of EJB.

The transaction is the group of employment which works fully or none to integrate and maintain the data. The transaction has special properties like atomicity, consistency, integrity, durability together calls them ACID. The completed transaction is Commitment of successful performance over unsuccessful performance.

Transaction management can be done in two methods.

  • Declarative Transaction Management
  • Programmatic Transaction Management.

Session facade is the design pattern used as a wrapper class. It is very important for the development of enterprise applications. It increases the performance of the system by minimize the network calls. Although it is executed as a high-level element (Session EJB it consists the interaction between low-level elements (Entity EJB). It also allowed the accessing of the client into bean elements.

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.

  • 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.

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.

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.

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.

  1. Entity- It is the representation of persistence data maintenance in the database.
  2. Entity Manager- It is used as an Interface. It is used to perform the various function like add, delete, Update, find etc. It is also used to handles the queries.
  3. Persistence unit- It is the collection of all the entity classes and used as the persistence mechanism.
  4. Data source- As the name suggests it is related to the data storage like properties.

Here are some advantages of the Java beam:

  • First, the developer doesn't need to take care of the handling, load balancing, logging, persistence mechanism and much more. As these services are provided by the EJB container. This helps the developer to concentrate only on the business logic.
  • The beam is designed in a very genuine way so that it can be run on different part of the geographical areas. So large scale business can be developed.
  • EJB container looks after the creation or deletion of the EJB objects.

Two components:

  1. Stateless session bean: It remains for a very short period of time. It is used when there is no need of worry of the state of the specific client. Validation of the credit card is a good example of the Stateless session beam.
  2. Stateful session beam: It has the unique feature which is absent in other beams that it can be implemented in the web whiles other cannot. It is used to maintain the conversation between the client. It saves the instance of conversation in the area like the hard disk before its proceeding into a passive state. Whenever the same client sends a request instance to come back to its original place (main memory). Online transaction, Online reservations are some examples of the Stateful session bean.

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.

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.

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.