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
EJB Interview Questions
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.
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.
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.
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.
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.
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.
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.
- 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.
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.
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.
15. 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.
Related Interview Questions
Kotlin 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
JUnit Interview Questions
Spring interview questions
Struts interview questions
Spring Boot Interview questions
Servlet interview questions
JDBC 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
- Core PHP Interview Questions