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.
EJB Interview Questions
- 1) What is EJB?
- 2) What are the various types of Entrepreneur java bean?
- 3) What are the various types of Entity beam?
- 4) What are the components of Session Beam?
- 5) What are the advantages of Java beam?
- 6) Explain the important elements of EJB?
- 7) Elucidate callback in EJB?
- 8) What do you mean by timer service and where it is used?
- 9) What are the callback annotations for the stateless bean?
- 10) Explain the concept of connection pooling feature of EJB container?
- 11) Is it possible to have threading in EJB?
- 12) What do you understand by Session facade?
- 13) Explain transaction and various methods to manage it?
- 14) What are the attributes of transaction in EJB?
- 15) Explain the concept of EJB QL?
- 16) What is the procedure for the creation of stateless EJB?
- 17) What do you understand by annotation in EJB to do the database entity relationships/mappings with examples?
- 18) What is the meaning of ACID in the connection of transaction management?
- 19) What are the callback annotations for entity bean?
- 20) What is the procedure for the presentation of EJP persistence mechanism?
- 21) How does EJB invocation happens?
- 22) Is EJB be called from another EJB? If yes then how?
- 23) What is JAR, WAR, and EAR?
- 24) What is the procedure of EJB container to handle exceptions?
- 25) Which services are provided to EJB components by the EJB container?
Below are the list of Best EJB Interview Questions and Answers
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.
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.
Entity beam is divided into two types: -
- 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.
- BMP Entity bean: BMP stands for Bean Managed Persistence. In this, develop has the duty or responsibility of all the database.
- 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.
- 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.
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.
- Entity- It is the representation of persistence data maintenance in the database.
- 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.
- Persistence unit- It is the collection of all the entity classes and used as the persistence mechanism.
- Data source- As the name suggests it is related to the data storage like properties.
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.
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.
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.
- 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.
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.
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.
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.
Here are some transaction attributes
- Required: No new transaction is created when the required attributed is linked to the transaction.
- Requires New: There is always present the addition of a new transaction when this attributed is linked to the transaction.
- Not Supported: If the method is linked to this attribute then the method does not remain part of the transaction
- 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.
- Mandatory: The method is always called from the calling element transaction context when the method is linked to this attribute.
- 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 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).
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.
17) What do you understand by annotation in EJB to do the database entity relationships/mappings with examples?
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.
- 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 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.
- 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.
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.
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.
- JAR contains all EJB class.
- WAR contains servlets, gif, HTML, applets, classes and many more.
- EAR contains both WAR and JAR files.
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.
Related Interview Questions
Core Java interview questions
Vaadin Interview Questions
Scala interview questions
Maven interview questions
OpenXava Interview questions
Java Play interview Questions
Groovy interview questions
Hibernate Interview Questions
Java Grails Interview Questions
Apache Ant Interview questions
Apache Kafka Interview Questions
Gradle Interview Questions
JSF Interview Questions
JSP Interview Questions
Spring interview questions
Struts interview questions
Spring Boot Interview questions
Servlet interview questions
JDBC interview questions
EJB Interview Questions
Struts 2 Interview Questions
Subscribe Our NewsLetter
Never Miss an Articles from us.
- Common Interview Questions
- Python Flask Interview Questions
- NoSQL interview questions
- JQuery Interview Questions
- C programming interview questions
- AngularJS Interview Questions
- Node JS Interview Questions with Express
- Core Java interview questions
- HTML Interview Questions
- Laravel interview questions
- Wordpress Interview Questions
- PHP Interview Questions