Technical interview questions and answers are crucial for clearing an EJB Interview because Enterprise JavaBeans are widely used in enterprise-level, distributed, and transactional applications. Companies evaluate your understanding of session beans, entity beans, message-driven beans, JNDI, lifecycle methods, and container-managed transactions. These concepts often appear in Java developer interviews conducted by TCS, Wipro, Infosys, Cognizant, and Accenture. For freshers and job seekers planning to enter Java-based development roles, EJB forms an important part of backend and enterprise Java interviews. This guide provides the most frequently asked EJB interview questions with answers, explained in simple language to help you understand real-time use cases. Preparing these questions will help you succeed in technical rounds and placement tests focused on Java EE technologies.
Java developers should also master J2EE concepts and explore J2SE fundamentals for comprehensive enterprise development expertise
Showing 10 of 54 questions
21. Can I develop an Entity Bean without implementing the create() method in the home interface?
As per the specifications, there can be ‘ZERO or ‘MORE create() methods defined in an Entity Bean. In cases where create() method is not provided, the only way to access the bean is by knowing its primary key, and by acquiring a handle to it by using its corresponding finder method. In those cases, you can create an instance of a bean based on the data present in the table. All one needs to know is the primary key of that table. i.e. a set a columns that uniquely identify a single row in that
22. What is the need of Remote and Home interface. Why cant it be in one?
The main reason is because there is a clear division of roles and responsibilities between the two interfaces. The home interface is your way to communicate with the container, that is who is responsible of creating, locating even removing one or more beans. The remote interface is your link to the bean, that will allow you to remotely access to all its methods and members. As you can see there are two distinct elements (the container and the beans) and you need two different interfaces for acce
23. What is bean managed transaction?
If a developer doesnt want a Container to manage transactions, Its possible to implement all database operations manually by writing the appropriate JDBC code. This often leads to productivity increase, but it makes an Entity Bean incompatible with some databases and it enlarges the amount of code to be written. All transaction management is explicitly performed by a developer.
24. What is an EJB Context?
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.
25. How can I call one EJB from inside of another EJB?
EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.
26. What happens if remove( ) is never invoked on a session bean?
In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container.
In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.
27. Can the primary key in the entity bean be a Java primitive type such as int?
The primary key cant be a primitive typeuse the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive)
28. What is an EJB Context?
EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions.
29. What happens if remove( ) is never invoked on a session bean?
In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container. In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.
30. How EJB Invocation happens?
Retrieve Home Object reference from Naming Service via JNDI. Return Home Object reference to the client. Create me a new EJB Object through Home Object interface. Create EJB Object from the Ejb Object. Return EJB Object reference to the client. Invoke business method using EJB Object reference. Delegate request to Bean (Enterprise Bean).