Interview Questions On Java,Java EE


Enter your email address:



Add to Technorati Favorites
Google PageRank Checker
Showing posts with label EJB. Show all posts
Showing posts with label EJB. Show all posts

Friday, May 18, 2007

Interview Questions on Enterprise Java Beans(EJB)

Continue reading...

What's difference between Servlet/JSP session and EJB session?

From a logical point of view, a Servlet/JSP session is similar to an EJB session. Using a session, in fact, a client can connect to a server and maintain his state.
But, is important to understand, that the session is maintained in different ways and, in theory, for different scopes.

A session in a Servlet, is maintained by the Servlet Container through the HttpSession object, that is acquired through the request object. You cannot really instantiate a new HttpSession object, and it doesn't contains any business logic, but is more of a place where to store objects.

A session in EJB is maintained using the SessionBeans. You design beans that can contain business logic, and that can be used by the clients. You have two different session beans: Stateful and Stateless. The first one is somehow connected with a single client. It maintains the state for that client, can be used only by that client and when the client "dies" then the session bean is "lost".

A Stateless Session Bean doesn't maintain any state and there is no guarantee that the same client will use the same stateless bean, even for two calls one after the other. The lifecycle of a Stateless Session EJB is slightly different from the one of a Stateful Session EJB. Is EJB Container's responsibility to take care of knowing exactly how to track each session and redirect the request from a client to the correct instance of a Session Bean. The way this is done is vendor dependant, and is part of the contract.
Continue reading...

What is Connection Pooling? Is it advantageous?

An EJB container provides the service of connection pooling in order to provide efficient way of database connectivity to its concurrent and continuous user requests. Whenever a client request for a database connection then an instance is picked from the connection pool to get an access to database as soon as user is through with his work instance is returned to connection pool. There is a limit specified by App server administrator for the availability of number of connections and beyond a specified limit a predefined number increases numbers of connection pool instances. When demand goes back to normal then access amount of connection pool instances are removed.

This mechanism of connection pooling helps in smart and efficient use of system resources and improving the overall performance of the whole system.
Continue reading...

What are the services provided by the EJB container ?

The container provides following services:
-Transaction Management
-Persistence
-Security
-Connection Pooling
-Naming services
Continue reading...

What is the difference between ejbCreate() and ejbPostCreate() in EntityBean?

An ejbCreate() method is called just before persisting the data into underlying database in case of Entity beans. It will create a new record in the database. A create () method defined in Home interface will correspond to an ejbCreate () method in bean class with the same arguments.

ejbPostCreate() is called by EjbContainer immediately after ejbCreate() method.This method may also be used to reset transaction related parameters.
Continue reading...

What is the difference between Container managed persistent and Bean managed persistent entity bean ?

The major difference between CMP and BMP Entity Beans is managing persistence of data through container in case of CMP and programmatically in BMP.
Generally, you should use CMP unless you're forced to use BMP due to limitations of the mapping tools. In case of mapping some relatively complex data models.
CMP is better than BMP as far as performance is concerned as in case of CMP through OR mapping optimization of transaction process is taken care off by container in the best possible manner. While in case of BMPs you can optimize your queries and improve performance over the generalized container-managed heuristics.
Continue reading...

How is container managed entity bean created?

A client first locates an EJB over network through JNDI and then gets a home interface reference on the EJB. On home interface the moment create() method is called; EJB container invokes underlying ejbCreate() method with similar method parameters, creating a persistent data in the underlying database.
Continue reading...

What are Entity Bean and Session Bean?

An Entity Bean is :
- a persistent business data object in a business process, which provides an OR (Object Relational) mapping over an underlying RDBMS.It is transactional in nature. An in memory objects can be mapped with a field of table in RDBMS database.
-can be expressed as a Noun e.g. a Customer, a Product, an Account, Purchase Order etc.
-long lasting as they represent data in the database.

Entity beans can be of two types:
CMP Entity Bean: EJB container manages data persistence and a bean developer do not have to bother about business data persistence logic.
BMP Entity Bean: A bean managed persistent entity bean is persisted in the database by hand or say programmatically. A component developer has to code to translate in memory objects to underlying RDBMS or object database.

A Session Bean incorporates business logic or business rules or workflow related logic of an enterprise. A session bean exists only until a session exists between a client and server so it has real short period of its existence.

Session beans are of two types:

Stateless Session Bean
In case where state between a client and a server interaction is not to be persisted then Stateless session bean is to be used. e.g. executing calculating tax or validating a credit card etc. The stateless bean instance does not have longevity.
Stateful Session Bean
Stateful Session bean keeps a conversational state of a client over a series of method calls, keeping it in a persistent area. They are more functional than stateless session bean as they store conversational state.

Whenever a client access a stateful session bean with a series of method calls, before moving the bean instance into passivated state, the conversational state is stored into the persistent area i.e. hard disk. This makes smart resource management. Whenever the same client is making a request again over the stateful session bean then state is pulled out of hard disk into in memory of bean. This is called activated state. Thus state of a client is saved in between context switching in a persistent storage area.
Continue reading...

How EJB evolved over the years?

The evolution of EJB can be captured in following points:
1.0:

- No mandate that Entity EJB must be supported by EJB container
- EJB communication backbone uses RMI-JRMP(Java Remote Method Protocol)
- No CMP Entity EJB
- No Deployment Descriptor XML file, used compiled class, then serializes it into flat file (binary).
1.1:
- Entity Bean supported by EJB container
- has CMP, but never describe how to configure relationship between CMP Entity EJBs, this depends on container tool provided by vendor
- RMI-IIOP is suggested for EJB communication
- Deployment Descriptor XML file was introduced
2.x:
- Message Driven Bean is introduced
- With CMP, you can configure the relationship between CMP Entity EJBs, in ejb-jar.xml
- EJB-QL for CMP EntityEJB query language
- RMI-IIOP is a must for EJB communication
3.0:
-No more deployment descriptor,metadata annotations used instead.
-CMP simplified.It is more like JDO or Hibernate.
-Checked exceptions are reduced.RemoteException is no longer mandatory with each remote business method .
-Inheritance is allowed and a bean can extend some base code.
-EJB-QL enhanced.
Continue reading...
 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker