EJB Interview Questions and Answers - Page 3

    1 Votes

24. What is an entity bean?

An entity bean is about storing persistent data in one row of a database table. When the client terminates or the server shuts down, the underlying services saves the entity bean data.
25. What is a message driven bean?

A message-driven bean includes features of a session bean and a Java Message Service, allowing a business component to receive messages asynchronously.

26. When we should use session bean?
  • Session bean should be used to model workflow, processes or tasks, manage activities (such as making reservation, purchase etc).
  • It should be used specific to a particular client.
  • It should be used to coordinate processes among entity beans.
27. What is a façade design pattern?

A design pattern that unifies many small interfaces into one big simplified one. It is wrapper around the small interfaces. Facade as an "object that provides a single, simplified interface to the more general facilities of a subsystem".

28. What are the types of a session bean?

  • Stateless: execute a request and return a result without saving any client specific state information
    • Transient
    • Temporary piece of business logic needed by a specific client for a limited time span.
  • Stateful: maintains client specific state.

29. What is a stateless session bean?

  • Does not retain client specific state from one method invocation to the next.
  • Bean instance can be reassigned to serve a method.
  • Invocation from another client once current method invocation is done.
  • Value of instance variables of a bean instance is not preserved between calls.

30. Give examples of a stateless session bean?


  • No client specific state needs to be preserved.
  • Common catalog data for all clients.

Interest calculator

  • No client specific state needs to be preserved.
  • Common business logic for all clients.

31. Explain the life cycle of a stateless session bean?

This is the pooled state.

In the ready state:

  • EJB Container Invokes the newInstance() method, which creates a new stateless session bean instance by calling the stateless session bean’s default constructor.
  • Invokes the setSessionContext() method to associate the bean’s instance with information about the environment in which bean instance will execute.
  • Invokes the ejbCreate() method defined in the stateless session bean class. The ejbCreate() method for a stateless session bean contains no arguments because a stateless session bean does not store client-specific information. (Only create and remove EJB Objects not instances.)

32. How container reuses stateless session bean instances?

Container transparently reuses bean instances to serve different clients

  • Pool of bean instances are created by container at appropriate time (ex: at the time of system boot or when the size of pool becomes too small).
  • Bean instances are then recycled.
  • Smaller number of bean instances (pool of bean instances) can serve larger number of clients at a single time.

33. Explain briefly about resource usage of stateless session beans?

  • Load-balancing & Failover (between EJB servers) is easier since no state needs to be preserved.
    • Any bean instance in any EJB server can serve any client call
  • High scalability since a client call can be served by any EJB server in a clustered architecture.
  • In order to handle increased number of clients, just add more memory or more EJB servers.

34. What is a home interface?

  • Defines methods for creating, finding and removing beans.
  • Implemented by Container
    • EJB home object.
  • Client gets “reference to stub object of the EJB home object” via JNDI.
  • Can be remote or local.

35. What is a remote or logic interface?

  • Defines business methods
    • Business methods are methods that deals with application specific business logic.
  • Implemented by Container
    • EJB object.
  • Client gets “reference to stub object of the EJB object” through create() or find() method of EJB Home interface.
  • Can be remote or local.

36. What are the advantages and disadvantages of local interface?


  • More efficient access due to co-location due to no RMI over IIOP overhead.
  • Ability to share data between client and bean through call by reference.


  • Tight coupling of client and bean.
  • Less flexibility in distribution.

37. What is EJB-JAR deployment descriptor?

  • Gives the container instructions on how to manage the enterprise bean.
  • Allows declarative customization.
  • Controls behaviors for:
    • Transaction
    • Security
    • Life cycle
    • State management
    • Persistence
Page 3 of 4

Popular Videos


How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

JSP Interview Questions and Answers
Servlet Interview Questions and Answers
Advanced Servlet Interview Questions and Answers
Spring Interview Questions and Answers