Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Develop n-tier applications using J2EE

An introduction to the Java 2 Platform, Enterprise Edition specification by way of BEA's WebLogic Server

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 4 of 7

Another database feature frequently required in enterprise applications is support for transactions. A transaction is a group of statements that should be treated as a single statement to ensure data integrity. JDBC uses the auto-commit transaction mode by default. This can be overridden using the setAutoCommit() method of the Connection class.

Now that we have a sense of JDBC, let's turn our attention to JNDI.

Java Naming and Directory Interface (JNDI)

The JNDI API is used to access naming and directory services. As such, it provides a consistent model for accessing and manipulating such enterprise-wide resources as DNS, LDAP, local filesystems, or objects in an application server.

In JNDI, every node in a directory structure is called a context. Every JNDI name is relative to a context; there is no notion of an absolute name. An application can obtain its first context using the InitialContext class:

Context ctx = new InitialContext();


From this initial context, the application can traverse the directory tree to locate the desired resources or objects. For example, assume that you have deployed an EJB within WebLogic Server and bound the home interface to the name myApp.myEJB. A client of this EJB, after obtaining an initial context, could then locate the home interface using:

MyEJBHome home = ctx.lookup( "myApp.myEJB" );


Once you have a reference to the acquired object -- in this case, the home interface of the EJB -- it is then possible to invoke methods on it. We will discuss this further in the section below entitled "Enterprise Java Beans."

The above discussion of JNDI is just the tip of the iceberg. In addition to looking up objects in a context, JNDI also provides methods to:

  • Insert, or bind, an object into a context. This is effectively what you do when you deploy an EJB.
  • Remove an object from a context.
  • List all objects within a context.
  • Create and delete subcontexts.


Next, let's turn our attention to EJBs.

Enterprise Java Beans (EJB)

One of the J2EE technologies to receive a great deal of media attention is EJBs. They provide a framework for developing and deploying distributed business logic to clients, thereby significantly easing the development of scalable, highly complex enterprise applications. The EJB specification defines how and when EJB components should interact with their container. It is the responsibility of the container to provide for common services, such as directory services, transaction management, security, resource pooling, and fault tolerance.

The EJBs specification defines three fundamental types of bean:

  • Stateless session beans: These provide a single-use service, do not maintain any state, do not survive server crashes, and are relatively short lived. For example, a stateless session bean may be used to perform temperature conversion.
  • Stateful session bean: These provide a conversational interaction with the client and, as such, store state on the behalf of the client. An online shopping cart is a classic example of a stateful session bean. Stateful session beans do not survive server crashes, are also relatively short lived, and each instance can be used only by a single thread.
  • Entity beans: These provide a representation of persistent data -- typically stored in a database -- and can therefore survive a server crash. Multiple clients can use EJBs that represent the same data. An example of an entity EJB: a customer's account information.


In spite of their differences, all EJBs have much in common. They all possess a home interface that defines how a client can create and destroy the EJB; a remote interface that defines the methods a client can invoke on the bean; and a bean class that implements the main business logic.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (4)
Login
Forgot your account info?

This article is almost 10 years oldBy Anonymous on September 21, 2009, 10:54 amDid anyone else notice this article is almost ten years old! It was posted on 12/01/2000

Reply | Read entire comment

Nice post about descriptionBy aimée andré on September 16, 2009, 5:50 amNice post about description J2EE. I like your blog very much because it has very interesting articles of different topics like 70-642 questions, 70-649 questions...

Reply | Read entire comment

lesson servletBy Anonymous on August 14, 2009, 2:07 pmno

Reply | Read entire comment

Description of J2EE along with application serverBy Anonymous on August 11, 2009, 6:17 amExplained clearly and with the beauty of simplicity added to it

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • JavaWorld resources
  • Other resources