Home Java Technology EJB EJB Sample Interview Questions - 1

Login Form




EJB Sample Interview Questions - 1 Print E-mail

1. The EJB container implements the EJBHome and EJBObject classes.For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
Answer: The EJB container maintains an instance pool.The container uses these instances for the EJB Home reference irrespective of the client request.while refering the EJB Object classes the container creates a separate instance for each client request.The instance pool maintainence is up to the implementation of the container.If the container provides one, it is available otherwise it is not mandatory for the provider to implement it.Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server.The way it is implemented is again up to the implementer.

2. What are the special design care that must be taken when you work with local interfaces?
Answer: EIt is important to understand that the calling semantics of local interfaces are different from those of remote interfaces.For example, remote interfaces pass parameters using call-by-value semantics, while local interfaces use call-by-reference.This means that in order to use local interfaces safely, application developers need to carefully consider potential deployment scenarios up front, then decide which interfaces can be local and which remote, and finally, develop the application code with these choices in mind.While EJB 2.0 local interfaces are extremely useful in some situations, the long-term costs of these choices, especially when changing requirements and component reuse are taken into account, need to be factored into the design decision.

3. 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.

4. 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.

5. 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.

6. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?
Answer: You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as ?passed-by-value", that means that it?s read-only in the EJB.If anything is altered from inside the EJB, it won?t be reflected back to the HttpSession of the Servlet Container.The ?pass-by-reference? can be used between EJBs Remote Interfaces, as they are remote references.While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be ?bad practice ? in terms of object oriented design.This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession).Create a higher-level of abstraction for your ejb?s api.Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end.Consider the case where your ejb needs to support a non-http-based client.This higher level of abstraction will be flexible enough to support it.

7. How does a container-managed relationship work?
Answer: An entity bean accesses related entity beans by means of the accessor methods for its container-managed relationship fields, which are specified by the cmr-field elements of its abstract persistence schema defined in the deployment descriptor.Entity bean relationships are defined in terms of the local interfaces of the related beans, and the view an entity bean presents to its related beans is defined by its local home and local interfaces.Thus, an entity bean can be the target of a relationship from another entity bean only if it has a local interface.

8. What is the need for Clustering?
Answer: To scale the application so that it is highly available and has high throughput.

9. What are the types of Scaling?
Answer: There are two types of scaling:

  • Vertical Scaling
  • Horizontal Scaling

10. What are the services that should not be used in a Clustered Environment?
Answer: The services that should not be used in Clustered Environment are:


File Services
Time services
Weblogic events
Weblogic Workspaces