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
1. What are the two important TCP Socket classes?
Answer: Socket and ServerSocket.
ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.
Show Answer
Hide Answer
2. What technologies are included in J2EE?
Answer: The main technologies in J2EE are: Enterprise JavaBeansTM (EJBsTM), JavaServer PagesTM (JSPsTM), Java Servlets, the Java Naming and Directory InterfaceTM (JNDITM), the Java Transaction API (JTA), CORBA, and the JDBCTM data access API.
Show Answer
Hide Answer
3. What is the difference between EJB and Java beans?
Answer: EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE.
Show Answer
Hide Answer
4. What is EJB role in J2EE?
Answer: EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.
Show Answer
Hide Answer
5. What is Enterprise JavaBeans (EJB) container?
Answer: It manages the execution of enterprise beans for J2EE applications.
Enterprise beans and their container run on the J2EE server.
Show Answer
Hide Answer
6. What is in-memory replication?
Answer: The process by which the contents in the memory of one physical m/c are replicated in all the m/c in the cluster is called in-memory replication.
Show Answer
Hide Answer
7. What is Ripple Effect?
Answer: The process of propagating the changes in the properties of a server group during runtime to all the associated clones is called Ripple Effect.
Show Answer
Hide Answer
8. What is a Clone?
Answer: The copies of a server group are called Clones. But unlike a Server Group Clones are associated with a node and are real server process running in that node.
Show Answer
Hide Answer
9. What are the types of Scaling
Answer: There are two types of scaling: Vertical Scaling and Horizontal Scaling.
Vertical Scaling - When multiple server clones of an application server are defined on the same physical m/c, it is called Vertical Scaling. The objective is to use the processing power of that m/c more efficiently.
Horizontal Scaling - When Clones of an application server are defined on multiple physical m/c, it is called Horizontal Scaling. The objective is to use more than one less powerful m/c more efficiently.
Show Answer
Hide Answer
10. What is a Server Group?
Answer: A server group is a template of an Application Server(and its contents) i.e, it is a logical representation of the application server. It has the same structure and attributes as the real Application Server, but it is not associated with any node, and does not correspond to any real server process running on any node.
Show Answer
Hide Answer
11. What is the new basic requirement for a CMP entity bean class in 2.0 from that of ejb 1.1?
Answer: It must be abstract class. The container extends it and implements methods which are required for managing the relationships
Show Answer
Hide Answer
12. whats new in the EJB 2.0 specification?
Answer: Following are some of the main features supported in EJB 2.0:
1. Integration of EJB with JMS,
2. Message Driven Beans,
3. Implement additional Business methods in Home interface which are not specific for bean instance, EJB QL.
Show Answer
Hide Answer
13. How can I access EJB from ASP?
Answer: We can use the Java 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0, currently downloadable from Sun
Show Answer
Hide Answer
14. What is the relationship between local interfaces and container-managed relationships?
Answer: Entity beans that have container-managed relationships with other entity beans, must be accessed in the same local scope as those related beans, and therefore typically provide a local client view. In order to be the target of a container-managed relationship, an entity bean with container-managed persistence must provide a local interface
Show Answer
Hide Answer
15. What is EJBDoclet?
Answer: EJBDoclet is an open source JavaDoc doclet that generates a lot of the EJB related source files from custom JavaDoc comments tags embedded in the EJB source file.
Show Answer
Hide Answer
16. What is the difference between session and entity beans?
Answer: An entity bean represents persistent global data from the database; a session bean represents transient user-specific data that will die when the user disconnects (ends his session). Generally, the session beans implement business methods (e.g. Bank.transferFunds) that call entity beans (e.g. Account.deposit, Account.withdraw)
Show Answer
Hide Answer
17. Is it legal to have static initializer blocks in EJB?
Answer: Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class. Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods
Show Answer
Hide Answer
18. What are transaction isolation levels in EJB?
Answer: 1. Transaction_read_uncommitted- Allows a method to read uncommitted data from a DB(fast but not wise).
2. Transaction_read_committed- Guarantees that the data you are getting has been committed.
3. Transaction_repeatable_read - Guarantees that all reads of the database will be the same during the transaction (good for read and update operations).
4. Transaction_serializable- All the transactions for resource are performed serial.
Show Answer
Hide Answer
19. Can Entity Beans have no create() methods?
Answer: Yes. In some cases the data is inserted NOT using Java application, so you may only need to retrieve the information, perform its processing, but not create your own information of this kind.
Show Answer
Hide Answer
20. When should I adopt BMP and when I should use CMP?
Answer: You can use CMP and BMP beans in the same application… obviously, a bean can be BMP or CMP, not both at the same time (they are mutually exclusive).
There is a common approach that is normally used and considered a good one. You should start developing CMP beans, unless you require some kind of special bean, like multi-tables, that cannot be completely realized with a single bean. Then, when you realize that you need something more or that you would prefer handling the persistence (performanb
Show Answer
Hide Answer
21. Can I develop an Entity Bean without implementing the create() method in the home interface?
Answer: 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
Show Answer
Hide Answer
22. What is the need of Remote and Home interface. Why cant it be in one?
Answer: 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
Show Answer
Hide Answer
23. What is bean managed transaction?
Answer: 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.
Show Answer
Hide Answer
24. What is an EJB Context?
Answer: 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.
Show Answer
Hide Answer
25. How can I call one EJB from inside of another EJB?
Answer: 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.
Show Answer
Hide Answer
26. What happens if remove( ) is never invoked on a session bean?
Answer: 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.
Show Answer
Hide Answer
27. Can the primary key in the entity bean be a Java primitive type such as int?
Answer: 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)
Show Answer
Hide Answer
28. What is an EJB Context?
Answer: 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.
Show Answer
Hide Answer
29. What happens if remove( ) is never invoked on a session bean?
Answer: 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.
Show Answer
Hide Answer
30. How EJB Invocation happens?
Answer: 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).
Show Answer
Hide Answer
31. How does a servlet communicate with a JSP page?
Answer: The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing.
Show Answer
Hide Answer
32. What is abstract schema?
Answer: Abstract schema is part of an entity beans deployment descriptor which defines the beans persistent fields and their relationship. Abstract schema is specified for entity beans with container managed persistence. We specify the name of the Abstract schema name in the deployment descriptor. The queries written in EJB QL for the finder methods references this name. The information provided in this Abstract Schema is used by the container for persistence management and relationship management.
Show Answer
Hide Answer
33. What is local interface. How values will be passed?
Answer: An EJB can use local client view only if it is really guaranteed that other enterprise beans or clients will only address the bean within a single JVM. With local client view, you can do pass-by-reference, which means your bean, as well as the client, will work directly with one copy of the data. Any changes made by the bean will be seen by the client and vice versa. Pass-by-reference eliminates time/system expenses for copying data variables, which provides a performance advantage.
Show Answer
Hide Answer
34. What is Message Driven Bean?
Answer: An MDB is essentially a message consumer that can listen to a message destination or a message endpoint and gets activated when a message arrives. By design, MDBs are anonymous in nature and hence cannot be directly invoked by a client. The only way to invoke an MDB is to send a message to the destination or endpoint to which it is listening. As MDBs are stateless in nature and are not related to any specific client, they can be pooled for concurrent processing of messages.
Show Answer
Hide Answer
35. What are the call back methods in Entity bean?
Answer: Callback methods allows the container to notify the bean of events in its life cycle. The callback methods are defined in the javax.ejb.EntityBean interface.
Show Answer
Hide Answer
36. What are the services provided by container?
Answer: Container services are totally depends upon the “vendor implementation”. But more or less most of the vendors suppots the basic services like,
LifeCycle Management - It is Automatic.
Session Management - it is used by Developer coded callback methods…
Transaction Management - it is used by configuring deployment descriptor (DD) .
Security management - it is used by configuring deployment descriptor (DD) .
The other services, if any will be in advanced versions, and depends on Vendor specifi
Show Answer
Hide Answer
37. What is deployment descriptor?
Answer: Deployment descriptor is a XML file. which is used to locate the web applicatio n by container.it includes the details of respective bean.
Show Answer
Hide Answer
38. How many EJB Objects are created for a Bean?
Answer: For a Session bean - one EJB object for one bean instance.
For entity bean - it depends , if 2 users are accessing one row at time then one EJB object is used for both the beans other wise for each bean one EJB object.
Show Answer
Hide Answer
39. What is re-entrant. Is session beans reentrant. Is entity beans reentrant?
Answer: If we define the entity bean as being reentrant, multiple clients can connect to the Entity bean & execute methods within the entity bean concurrently. Container takes care of synchronization. If we define the entity bean as non-reentrant and many clients connect to it concurrently to execute a method, exception is thrown .
Show Answer
Hide Answer
40. Can i map more than one table in a CMP?
Answer: No, you cannot map more than one table to a single CMP Entity Bean. CMP has been, in fact, designed to map a single table.
Show Answer
Hide Answer
41. Is Decorator an EJB design pattern?
Answer: No. Decorator design pattern, is the one which exhibits very low level runtime polymorphism, for the specific and single object (Instance of the class), but not for atleast for a class. It is the stuff to add specific functionality to a single & pointed object and leaves others like it unmodified. It is having close similarities like aspectJ stuff, but not with EJB stuff.
Show Answer
Hide Answer
42. What is the difference between sessioncontext and entitycontext?
Answer: Since EnterpriseBeans live in a managed container, the container is free to call your EJB components methods at its leisure. The container houses the information like current status of bean,security credentials of the user currently accessing the bean in one object is called EJBContext Object. A context represents a way for beans to perform callbacks and modify their current status Sessioncontext is EJB context for session bean Entitycontext is EJB context for entity bean Message driven context
Show Answer
Hide Answer
43. Does stateless Session bean create() method contain any parameters?
Answer: Stateless SessionBean create() method doesnot contain any parameters and the syntax is as follows:
public interface XSessionEJBHome extends EJBHome
{
XSessionEJB create() throws RemoteException, CreateException;
}
Show Answer
Hide Answer
44. What is difference between EJB 1.1 and EJB 2.0?
Answer: The bulk of the changes in EJB 2.0 are found in the definition of a new CMP component model. Its radically different from the old CMP model because it introduces an entirely new participant, the persistence manager, and a completely new way of defining container-managed fields, as well as relationships with other beans and dependent objects.
Show Answer
Hide Answer
45. What is the difference between ejbCreate() and ejbPostCreate
Answer: The purpose of ejbPostCreate() is to perform clean-up database operations after SQL INSERTs (which occur when ejbCreate() is called) when working with CMP entity beans. ejbCreate() is called before database INSERT operations. You need to use ejbPostCreate() to define operations, like set a flag, after INSERT completes successfully.
Show Answer
Hide Answer
46. Why does EJB needs two interfaces(Home and Remote Interface)
Answer: There is a pure division of roles between the two .
Home Interface is the way to communicate with the container which is responsible for creating , locating and removing beans and Remote Interface is the link to the bean that allows acces to all methods and members.
Show Answer
Hide Answer
47. What are the optional clauses in EJB QL?
Answer: WHERE and ORDERBY clauses are optional in EJB QL where as SELECT and FROM are required clauses.
Show Answer
Hide Answer
48. Can I invoke Runtime.gc() in an EJB?
Answer: You shouldnt. What will happen depends on the implementation, but the call will most likely be ignored.
Show Answer
Hide Answer
49. What is Remote client view?
Answer: The remote client view specification is only available in EJB 2.0. The remote client view of an enterprise bean is location independent. A client running in the same JVM as a bean instance uses the same API to access the bean as a client running in a different JVM on the same or different machine.
Remote interface: The remote interface specifies the remote business methods that a client can call on an enterprise bean.
Remote home interface: The remote home interface specifies the methods used
Show Answer
Hide Answer
50. What is Local client view?
Answer: The local client view specification is only available in EJB 2.0. Unlike the remote client view, the local client view of a bean is location dependent. Local client view access to an enterprise bean requires both the local client and the enterprise bean that provides the local client view to be in the same JVM. The local client view therefore does not provide the location transparency provided by the remote client view. Local interfaces and local home interfaces provide support for lightweight a
Show Answer
Hide Answer
51. What is EJB client JAR file?
Answer: An EJB client JAR file is an optional JAR file that can contain all the class files that a client program needs to use the client view of the enterprise beans that are contained in the EJB JAR file. If you decide not to create a client JAR file for an EJB module, all of the client interface classes will be in the EJB JAR file.
Show Answer
Hide Answer
52. What is EJB container?
Answer: An EJB container is a run-time environment that manages one or more enterprise beans. The EJB container manages the life cycles of enterprise bean objects, coordinates distributed transactions, and implements object security. Generally, each EJB container is provided by an EJB server and contains a set of enterprise beans that run on the server.
Show Answer
Hide Answer
53. What is Deployment descriptor?
Answer: A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR file or an EAR file. It contains metadata describing the contents and structure of the enterprise beans, and runtime transaction and security information for the EJB container.
Show Answer
Hide Answer
54. What is EJB server?
Answer: An EJB server is a high-level process or application that provides a run-time environment to support the execution of server applications that use enterprise beans. An EJB server provides a JNDI-accessible naming service, manages and coordinates the allocation of resources to client applications, provides access to system resources, and provides a transaction service. An EJB server could be provided by, for example, a database or application server.
Show Answer
Hide Answer