Showing posts with label Technology. Show all posts
Showing posts with label Technology. Show all posts

Friday, June 15, 2012

J2EE Tutorial-15(Running the Web Client)

To run the Web client, point your browser at the following URL. Replace <host> with the name of the host running the J2EE server. If your browser is running on the same host as the J2EE server, you may replace <host>with localhost.

http://<host>:8000/converter


You should see the screen shown in Figure 2-2 after entering 100 in the input field and clicking Submit.



Figure 2-2 Converter Web Client

J2EE Tutorial-12(Specifying the JNDI Names)

Although the J2EE application client and the Web client access the same enterprise bean, their code refers to the bean's home by different names. The J2EE application client refers to the bean's home asejb/SimpleConverter, but the Web client refers to it as ejb/TheConverter. These references are in the parameters of the lookup calls. In order for the lookup method to retrieve the home object, you must map the references in the code to the enterprise bean's JNDI name. Although this mapping adds a level of indirection, it decouples the clients from the beans, making it easier to assemble applications from J2EE components.

To map the enterprise bean references in the clients to the JNDI name of the bean, follow these steps.

  1. In the tree, select ConverterApp.

  2. Select the JNDI Names tab.

  3. To specify a JNDI name for the bean, in the Application table locate the ConverterEJB component and enter MyConverter in the JNDI Name column.

  4. To map the references, in the References table enter MyConverter in the JNDI Name for each row.


Figure 2-1 shows what the JNDI Names tab should look like after you've performed the preceding steps.



 

Figure 2-1 ConverterApp JNDI Names

Wednesday, May 30, 2012

J2EE Tutorial-9(Creating the Enterprise Bean)

An enterprise bean is a server-side component that contains the business logic of an application. At runtime, the application clients execute the business logic by invoking the enterprise bean's methods. The enterprise bean in our example is a stateless session bean called ConverterEJB. The source code for ConverterEJB is in thej2eetutorial/examples/src/ejb/converter directory.

Coding the Enterprise Bean


The enterprise bean in this example requires the following code:

  • Remote interface

  • Home interface

  • Enterprise bean class


Coding the Remote Interface


A remote interface defines the business methods that a client may call. The business methods are implemented in the enterprise bean code. The source code for the Converter remote interface follows.

import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;

public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen)
throws RemoteException;
}


Coding the Home Interface


home interface defines the methods that allow a client to create, find, or remove an enterprise bean. The ConverterHome interface contains a single create method, which returns an object of the remote interface type. Here is the source code for the ConverterHome interface:

import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface ConverterHome extends EJBHome {
Converter create() throws RemoteException, CreateException;
}


Coding the Enterprise Bean Class


The enterprise bean class for this example is called ConverterBean. This class implements the two business methods, dollarToYen and yenToEuro, that the Converter remote interface defines. The source code for the ConverterBean class follows.

import java.rmi.RemoteException; 
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;

public class ConverterBean implements SessionBean {

BigDecimal yenRate = new BigDecimal("121.6000");
BigDecimal euroRate = new BigDecimal("0.0077");

public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}


Compiling the Source Files


Now you are ready to compile the remote interface (Converter.java), home interface (ConverterHome.java), and the enterprise bean class (ConverterBean.java).

  1. In a terminal window, go to the j2eetutorial/examples directory.

  2. Type the following command:

       ant converter




This command compiles the source files for the enterprise bean and the J2EE application client. It places the resulting class files in thej2eetutorial/examples/build/ejb/converter directory (not the src directory). For more information about ant, see How to Build and Run the Examples.




Note: When compiling the code, the preceding ant task includes the j2ee.jar file in the classpath. This file resides in the lib directory of your J2EE SDK installation. If you plan on using other tools to compile the source code for J2EE components, make sure that the classpath includes the j2ee.jar file.




Packaging the Enterprise Bean


To package an enterprise bean, you run the New Enterprise Bean wizard of the deploytool utility. During this process, the wizard performs the following tasks:

  • Creates the bean's deployment descriptor

  • Packages the deployment descriptor and the bean's classes in an EJB JAR file

  • Inserts the EJB JAR file into the application's ConverterApp.ear file


After the packaging process, you can view the deployment descriptor by selecting ToolsDescriptor Viewer.

To start the New Enterprise Bean wizard, select FileNewEnterprise Bean. The wizard displays the following dialog boxes.

  1. Introduction dialog box

    1. Read the explanatory text for an overview of the wizard's features.

    2. Click Next.



  2. EJB JAR dialog box

    1. Select the Create New JAR File In Application button.

    2. In the combo box, select ConverterApp.

    3. In the JAR Display Name field, enter ConverterJAR.

    4. Click Edit.

    5. In the tree under Available Files, locate the j2eetutorial/examples/build/ejb/converter directory. (If the converter directory is many levels down in the tree, you can simplify the tree view by entering all or part of the converter directory's path name in the Starting Directory field.)

    6. Select the following classes from the Available Files tree and click Add: Converter.classConverterBean.class, and ConverterHome.class. (You may also drag and drop these class files to the Contents text area.)

    7. Click OK.

    8. Click Next.



  3. General dialog box

    1. Under Bean Type, select the Session radio button.

    2. Select the Stateless radio button.

    3. In the Enterprise Bean Class combo box, select ConverterBean.

    4. In the Enterprise Bean Name field, enter ConverterEJB.

    5. In the Remote Home Interface combo box, select ConverterHome.

    6. In the Remote Interface combo box, select Converter.

    7. Click Next.



  4. Transaction Management dialog box

    1. Because you may skip the remaining dialog boxes, click Finish.



J2EE Tutorial-8 (Creating the J2EE Application)

The sample application contains three J2EE components: an enterprise bean, a J2EE application client, and a Web component. Before building these components, you will create a new J2EE application called ConverterApp and will store it in an EAR file named ConverterApp.ear.

  1. In deploytool, select FileNewApplication.

  2. Click Browse.

  3. In the file chooser, navigate to j2eetutorial/examples/src/ejb/converter.

  4. In the File Name field, enter ConverterApp.ear.

  5. Click New Application.

  6. Click OK.

J2EE Tutorial-7 (Setting up Environment)

Before you start developing the example application, you should follow the instructions in this section.

Getting the Example Code


The source code for the components is in j2eetutorial/examples/src/ejb/converter, a directory that is created when you unzip the tutorial bundle. If you are viewing this tutorial online, you need to download the tutorial bundle from

http://java.sun.com/j2ee/download.html#tutorial 


Getting the Build Tool (ant)


To build the example code, you'll need installations of the J2EE SDK and ant, a portable make tool. For more information, see the section How to Build and Run the Examples.

Checking the Environment Variables


The installation instructions for the J2EE SDK and ant explain how to set the required environment variables. Verify that the environment variables have been set to the values noted inTable 2-1.

 























Table 2-1 Required Environment Variables
Environment Variable
Value
JAVA_HOMEThe location of the J2SE SDK installation
J2EE_HOMEThe location of the J2EE SDK installation
ANT_HOMEThe location of the ant installation
PATHShould include the bin directories of the J2EE SDK, J2SE, and ant installations

 

Starting the J2EE Server


To launch the J2EE server, open a terminal window and type this command:

j2ee -verbose


Although not required, the verbose option is useful for debugging.

To stop the server, type the following command:

j2ee -stop


Starting the deploytool


The deploytool utility has two modes: command line and GUI. The instructions in this chapter refer to the GUI version. To start the deploytool GUI, open a terminal window and type this command:

deploytool

J2EE Tutorial-6 (Reference Implementation Software)

The J2EE SDK is a noncommercial operational definition of the J2EE platform and specification made freely available by Sun Microsystems for demonstrations, prototyping, and educational use. It comes with the J2EE application server, Web server, relational database, J2EE APIs, and complete set of development and deployment tools. You can download the J2EE SDK from

http://java.sun.com/j2ee/download.html#sdk 


The purpose of the J2EE SDK is to allow product providers to determine what their implementations must do under a given set of application conditions, and to run the J2EE Compatibility Test Suite to test that their J2EE products fully comply with the specification. It also allows application component developers to run their J2EE applications on the J2EE SDK to verify that applications are fully portable across all J2EE products and tools.

Database Access


The relational database provides persistent storage for application data. A J2EE implementation is not required to support a particular type of database, which means that the database supported by different J2EE products can vary. See the Release Notes included with the J2EE SDK download for a list of the databases currently supported by the reference implementation.

J2EE APIs


The Java 2 Platform, Standard Edition (J2SE) SDK is required to run the J2EE SDK and provides core APIs for writing J2EE components, core development tools, and the Java virtual machine. The J2EE SDK provides the following APIs to be used in J2EE applications.

Enterprise JavaBeans Technology 2.0


An enterprise bean is a body of code with fields and methods to implement modules of business logic. You can think of an enterprise bean as a building block that can be used alone or with other enterprise beans to execute business logic on the J2EE server.

There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans. Enterprise beans often interact with databases. One of the benefits of entity beans is that you do not have to write any SQL code or use the JDBC API directly to perform database access operations; the EJB container handles this for you. However, if you override the default container-managed persistence for any reason, you will need to use the JDBC API. Also, if you choose to have a session bean access the database, you have to use the JDBC API.

JDBC API 2.0


The JDBC API lets you invoke SQL commands from Java programing language methods. You use the JDBC API in an enterprise bean when you override the default container-managed persistence or have a session bean access the database. With container-managed persistence, database access operations are handled by the container, and your enterprise bean implementation contains no JDBC code or SQL commands. You can also use the JDBC API from a servlet or JSP page to access the database directly without going through an enterprise bean.

The JDBC API has two parts: an application-level interface used by the application components to access a database, and a service provider interface to attach a JDBC driver to the J2EE platform.

Java Servlet Technology 2.3


Java Servlet technology lets you define HTTP-specific servlet classes. A servlet class extends the capabilities of servers that host applications accessed by way of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by Web servers.

JavaServer Pages Technology 1.2


JavaServer Pages technology lets you put snippets of servlet code directly into a text-based document. A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, WML, and XML, and JSP elements, which determine how the page constructs dynamic content.

Java Message Service 1.0


The JMS is a messaging standard that allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous. For more information on JMS, see the online Java Message Service Tutorial:

http://java.sun.com/products/jms/tutorial/index.html 


Java Naming and Directory Interface 1.2


The JNDI provides naming and directory functionality. It provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes. Using JNDI, a J2EE application can store and retrieve any type of named Java object.

Because JNDI is independent of any specific implementations, applications can use JNDI to access multiple naming and directory services, including existing naming and directory services such as LDAP, NDS, DNS, and NIS. This allows J2EE applications to coexist with legacy applications and systems. For more information on JNDI, see the online JNDI Tutorial:

http://java.sun.com/products/jndi/tutorial/index.html 


Java Transaction API 1.0


The Java Transaction API ("JTA") provides a standard interface for demarcating transactions. The J2EE architecture provides a default auto commit to handle transaction commits and rollbacks. An auto commit means that any other applications viewing data will see the updated data after each database read or write operation. However, if your application performs two separate database access operations that depend on each other, you will want to use the JTA API to demarcate where the entire transaction, including both operations, begins, rolls back, and commits.

JavaMail API 1.2


J2EE applications can use the JavaMail API to send e-mail notifications. The JavaMail API has two parts: an application-level interface used by the application components to send mail, and a service provider interface. The J2EE platform includes JavaMail with a service provider that allows application components to send Internet mail.

JavaBeans Activation Framework 1.0


The JavaBeans Activation Framework ("JAF") is included because JavaMail uses it. It provides standard services to determine the type of an arbitrary piece of data, encapsulate access to it, discover the operations available on it, and create the appropriate JavaBeans component to perform those operations.

Java API for XML Processing 1.1


XML is a language for representing text-based data so the data can be read and handled by any program or tool. Programs and tools can generate XML documents that other programs and tools can read and handle. The Java API for XML Processing ("JAXP") supports processing of XML documents using DOM, SAX, and XSLT. JAXP enables applications to parse and transform XML documents independent of a particular XML processing implementation.

For example, a J2EE application can use XML to produce reports, and different companies that receive the reports can handle the data in a way that best suits their needs. One company might put the XML data through a program to translate the XML to HTML so it can post the reports to the Web, another company might put the XML data through a tool to create a marketing presentation, and yet another company might read the XML data into its J2EE application for processing.

J2EE Connector Architecture 1.0


The J2EE Connector architecture is used by J2EE tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged into any J2EE product. A resource adapter is a software component that allows J2EE application components to access and interact with the underlying resource manager. Because a resource adapter is specific to its resource manager, there is typically a different resource adapter for each type of database or enterprise information system.

Java Authentication and Authorization Service 1.0


The Java Authentication and Authorization Service ("JAAS") provides a way for a J2EE application to authenticate and authorize a specific user or group of users to run it.

JAAS is a Java programing language version of the standard Pluggable Authentication Module (PAM) framework that extends the Java 2 Platform security architecture to support user-based authorization.

Simplified Systems Integration


The J2EE platform is a platform-independent, full systems integration solution that creates an open marketplace in which every vendor can sell to every customer. Such a marketplace encourages vendors to compete, not by trying to lock customers into their technologies but by trying to outdo each other by providing products and services that benefit customers, such as better performance, better tools, or better customer support.

The J2EE APIs enable systems and applications integration through the following:

  • Unified application model across tiers with enterprise beans

  • Simplified response and request mechanism with JSP pages and servlets

  • Reliable security model with JAAS

  • XML-based data interchange integration with JAXP

  • Simplified interoperability with the J2EE Connector Architecture

  • Easy database connectivity with the JDBC API

  • Enterprise application integration with message-driven beans and JMS, JTA, and JNDI


You can learn more about using the J2EE platform to build integrated business systems by reading J2EE Technology in Practice.

Tools


The J2EE reference implementation provides an application deployment tool and an array of scripts for assembling, verifying, and deploying J2EE applications and managing your development and production environments. See Appendix B for a discussion of the tools.

Application Deployment Tool


The J2EE reference implementation provides an application deployment tool (deploytool) for assembling, verifying, and deploying J2EE applications. There are two versions: command line and GUI.

The GUI tool includes wizards for:

  • Packaging, configuring, and deploying J2EE applications

  • Packaging and configuring enterprise beans

  • Packaging and configuring Web components

  • Packaging and configuring application clients

  • Packaging and configuring resource adaptors


In addition, configuration information can be set for each component and module type in the tabbed inspector panes.

Scripts


Table 1-1 lists the scripts included with the J2EE reference implementation that let you perform operations from the command line.



 











































Table 1-1 J2EE Scripts 
ScriptDescription
j2eeStart and stop the J2EE server
cloudscapeStart and stop the default database
j2eeadminAdd JDBC drivers, JMS destinations, and connection factories for various resources
keytoolCreate public and private keys and generate X509 self-signed certificate
realmtoolImport certificate files, add J2EE users to and remove J2EE users from the authentication and authorization list for a J2EE application
packagerPackage J2EE application components into EAR, EJB JAR, application client JAR, and WAR files
verifierVerify that EAR, EJB JAR, application client JAR, and WAR files are well-formed and comply with the J2EE specification
runclientRun a J2EE application client
cleanupRemove all deployed applications from the J2EE server

Tuesday, May 29, 2012

J2EE Tutorial-5 (Development Roles)

Reusable modules make it possible to divide the application development and deployment process into distinct roles so that different people or companies can perform different parts of the process.

The first two roles involve purchasing and installing the J2EE product and tools. Once software is purchased and installed, J2EE components can be developed by application component providers, assembled by application assemblers, and deployed by application deployers. In a large organization, each of these roles might be executed by different individuals or teams. This division of labor works because each of the earlier roles outputs a portable file that is the input for a subsequent role. For example, in the application component development phase, an enterprise bean software developer delivers EJB JAR files. In the application assembly role, another developer combines these EJB JAR files into a J2EE application and saves it in an EAR file. In the application deployment role, a system administrator at the customer site uses the EAR file to install the J2EE application into a J2EE server.

The different roles are not always executed by different people. If you work for a small company, for example, or if you are prototyping a sample application, you might perform the tasks in every phase.

J2EE Product Provider


The J2EE product provider is the company that designs and makes available for purchase the J2EE platform, APIs, and other features defined in the J2EE specification. Product providers are typically operating system, database system, application server, or Web server vendors who implement the J2EE platform according to the Java 2 Platform, Enterprise Edition Specification.

Tool Provider


The tool provider is the company or person who creates development, assembly, and packaging tools used by component providers, assemblers, and deployers. See the section Tools for information on the tools available with J2EE SDK version 1.3.

Application Component Provider


The application component provider is the company or person who creates Web components, enterprise beans, applets, or application clients for use in J2EE applications.

Enterprise Bean Developer


An enterprise bean developer performs the following tasks to deliver an EJB JAR file that contains the enterprise bean:

  • Writes and compiles the source code

  • Specifies the deployment descriptor

  • Bundles the .class files and deployment descriptor into an EJB JAR file


Web Component Developer


A Web component developer performs the following tasks to deliver a WAR file containing the Web component:

  • Writes and compiles servlet source code

  • Writes JSP and HTML files

  • Specifies the deployment descriptor for the Web component

  • Bundles the .class.jsp.html, and deployment descriptor files in the WAR file


J2EE Application Client Developer


An application client developer performs the following tasks to deliver a JAR file containing the J2EE application client:

  • Writes and compiles the source code

  • Specifies the deployment descriptor for the client

  • Bundles the .class files and deployment descriptor into the JAR file


Application Assembler


The application assembler is the company or person who receives application component JAR files from component providers and assembles them into a J2EE application EAR file. The assembler or deployer can edit the deployment descriptor directly or use tools that correctly add XML tags according to interactive selections. A software developer performs the following tasks to deliver an EAR file containing the J2EE application:

  • Assembles EJB JAR and WAR files created in the previous phases into a J2EE application (EAR) file

  • Specifies the deployment descriptor for the J2EE application

  • Verifies that the contents of the EAR file are well formed and comply with the J2EE specification


Application Deployer and Administrator


The application deployer and administrator is the company or person who configures and deploys the J2EE application, administers the computing and networking infrastructure where J2EE applications run, and oversees the runtime environment. Duties include such things as setting transaction controls and security attributes and specifying connections to databases.

During configuration, the deployer follows instructions supplied by the application component provider to resolve external dependencies, specify security settings, and assign transaction attributes. During installation, the deployer moves the application components to the server and generates the container-specific classes and interfaces.

A deployer/system administrator performs the following tasks to install and configure a J2EE application:

  • Adds the J2EE application (EAR) file created in the preceding phase to the J2EE server

  • Configures the J2EE application for the operational environment by modifying the deployment descriptor of the J2EE application

  • Verifies that the contents of the EAR file are well formed and comply with the J2EE specification

  • Deploys (installs) the J2EE application EAR file into the J2EE server

J2EE Tutorial-4 (Packaging)



J2EE components are packaged separately and bundled into a J2EE application for deployment. Each component, its related files such as GIF and HTML files or server-side utility classes, and a deployment descriptor are assembled into a module and added to the J2EE application. A J2EE application is composed of one or more enterprise bean, Web, or application client component modules. The final enterprise solution can use one J2EE application or be made up of two or more J2EE applications, depending on design requirements.

A J2EE application and each of its modules has its own deployment descriptor. A deployment descriptor is an XML document with an .xml extension that describes a component's deployment settings. An enterprise bean module deployment descriptor, for example, declares transaction attributes and security authorizations for an enterprise bean. Because deployment descriptor information is declarative, it can be changed without modifying the bean source code. At run time, the J2EE server reads the deployment descriptor and acts upon the component accordingly.

A J2EE application with all of its modules is delivered in an Enterprise Archive (EAR) file. An EAR file is a standard Java Archive (JAR) file with an .ear extension. In the GUI version of the J2EE SDK application deployment tool, you create an EAR file first and add JAR and Web Archive (WAR) files to the EAR. If you use the command line packager tools, however, you create the JAR and WAR files first and then create the EAR. The J2EE SDK tools are described in the section Tools.

  • Each EJB JAR file contains a deployment descriptor, the enterprise bean files, and related files.

  • Each application client JAR file contains a deployment descriptor, the class files for the application client, and related files.

  • Each WAR file contains a deployment descriptor, the Web component files, and related resources.


Using modules and EAR files makes it possible to assemble a number of different J2EE applications using some of the same components. No extra coding is needed; it is just a matter of assembling various J2EE modules into J2EE EAR files.

J2EE Tutorial-3 (J2EE Containers)

J2EE Containers


Normally, thin-client multitiered applications are hard to write because they involve many lines of intricate code to handle transaction and state management, multithreading, resource pooling, and other complex low-level details. The component-based and platform-independent J2EE architecture makes J2EE applications easy to write because business logic is organized into reusable components. In addition, the J2EE server provides underlying services in the form of a container for every component type. Because you do not have to develop these services yourself, you are free to concentrate on solving the business problem at hand.

Container Services


Containers are the interface between a component and the low-level platform-specific functionality that supports the component. Before a Web, enterprise bean, or application client component can be executed, it must be assembled into a J2EE application and deployed into its container.

The assembly process involves specifying container settings for each component in the J2EE application and for the J2EE application itself. Container settings customize the underlying support provided by the J2EE server, which includes services such as security, transaction management, Java Naming and Directory Interface (JNDI) lookups, and remote connectivity. Here are some of the highlights:

  • The J2EE security model lets you configure a Web component or enterprise bean so that system resources are accessed only by authorized users.

  • The J2EE transaction model lets you specify relationships among methods that make up a single transaction so that all methods in one transaction are treated as a single unit.

  • JNDI lookup services provide a unified interface to multiple naming and directory services in the enterprise so that application components can access naming and directory services.

  • The J2EE remote connectivity model manages low-level communications between clients and enterprise beans. After an enterprise bean is created, a client invokes methods on it as if it were in the same virtual machine.


The fact that the J2EE architecture provides configurable services means that application components within the same J2EE application can behave differently based on where they are deployed. For example, an enterprise bean can have security settings that allow it a certain level of access to database data in one production environment and another level of database access in another production environment.

The container also manages nonconfigurable services such as enterprise bean and servlet life cycles, database connection resource pooling, data persistence, and access to the J2EE platform APIs described in the section J2EE APIs. Although data persistence is a nonconfigurable service, the J2EE architecture lets you override container-managed persistence by including the appropriate code in your enterprise bean implementation when you want more control than the default container-managed persistence provides. For example, you might use bean-managed persistence to implement your own finder (search) methods or to create a customized database cache.

Container Types


The deployment process installs J2EE application components in the J2EE containers illustrated in Figure 1-5.



 

Figure 1-5 J2EE Server and Containers



J2EE server
 



The runtime portion of a J2EE product. A J2EE server provides EJB and Web containers. 



Enterprise JavaBeans (EJB) container
 



Manages the execution of enterprise beans for J2EE applications. Enterprise beans and their container run on the J2EE server. 



Web container
 



Manages the execution of JSP page and servlet components for J2EE applications. Web components and their container run on the J2EE server. 



Application client container
 



Manages the execution of application client components. Application clients and their container run on the client. 



Applet container
 



Manages the execution of applets. Consists of a Web browser and Java Plug-in running on the client together.

J2EE Tutorial-3 (J2EE Components)

J2EE Components


J2EE applications are made up of components. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. The J2EE specification defines the following J2EE components:

  • Application clients and applets are components that run on the client.

  • Java Servlet and JavaServer Pages (JSP) technology components are Web components that run on the server.

  • Enterprise JavaBeans (EJB) components (enterprise beans) are business components that run on the server.


J2EE components are written in the Java programming language and are compiled in the same way as any program in the language. The difference between J2EE components and "standard" Java classes is that J2EE components are assembled into a J2EE application, verified to be well formed and in compliance with the J2EE specification, and deployed to production, where they are run and managed by the J2EE server.

J2EE Clients


A J2EE client can be a Web client or an application client.

Web Clients


A Web client consists of two parts: dynamic Web pages containing various types of markup language (HTML, XML, and so on), which are generated by Web components running in the Web tier, and a Web browser, which renders the pages received from the server.

A Web client is sometimes called a thin client. Thin clients usually do not do things like query databases, execute complex business rules, or connect to legacy applications. When you use a thin client, heavyweight operations like these are off-loaded to enterprise beans executing on the J2EE server where they can leverage the security, speed, services, and reliability of J2EE server-side technologies.

Applets


A Web page received from the Web tier can include an embedded applet. An applet is a small client application written in the Java programming language that executes in the Java virtual machine installed in the Web browser. However, client systems will likely need the Java Plug-in and possibly a security policy file in order for the applet to successfully execute in the Web browser.

Web components are the preferred API for creating a Web client program because no plug-ins or security policy files are needed on the client systems. Also, Web components enable cleaner and more modular application design because they provide a way to separate applications programming from Web page design. Personnel involved in Web page design thus do not need to understand Java programming language syntax to do their jobs.

Application Clients


A J2EE application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a markup language. It typically has a graphical user interface (GUI) created from Swing or Abstract Window Toolkit (AWT) APIs, but a command-line interface is certainly possible.

Application clients directly access enterprise beans running in the business tier. However, if application requirements warrant it, a J2EE application client can open an HTTP connection to establish communication with a servlet running in the Web tier.

JavaBeans Component Architecture


The server and client tiers might also include components based on the JavaBeans component architecture (JavaBeans component) to manage the data flow between an application client or applet and components running on the J2EE server or between server components and a database. JavaBeans components are not considered J2EE components by the J2EE specification.

JavaBeans components have instance variables and get and set methods for accessing the data in the instance variables. JavaBeans components used in this way are typically simple in design and implementation, but should conform to the naming and design conventions outlined in the JavaBeans component architecture.

J2EE Server Communications


Figure 1-2 shows the various elements that can make up the client tier. The client communicates with the business tier running on the J2EE server either directly or, as in the case of a client running in a browser, by going through JSP pages or servlets running in the Web tier.

Your J2EE application uses a thin browser-based client or thick application client. In deciding which one to use, you should be aware of the trade-offs between keeping functionality on the client and close to the user (thick client) and off-loading as much functionality as possible to the server (thin client). The more functionality you off-load to the server, the easier it is to distribute, deploy, and manage the application; however, keeping more functionality on the client can make for a better perceived user experience.



 

Figure 1-2 Server Communications

Web Components


J2EE Web components can be either servlets or JSP pages. Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.

Static HTML pages and applets are bundled with Web components during application assembly, but are not considered Web components by the J2EE specification. Server-side utility classes can also be bundled with Web components and, like HTML pages, are not considered Web components.

Like the client tier and as shown in Figure 1-3, the Web tier might include a JavaBeans component to manage the user input and send that input to enterprise beans running in the business tier for processing.

Business Components


Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier.Figure 1-4 shows how an enterprise bean receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.



 

Figure 1-3 Web Tier and J2EE Application



 

Figure 1-4 Business and EIS Tiers

There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans. A session bean represents a transient conversation with a client. When the client finishes executing, the session bean and its data are gone. In contrast, an entity bean represents persistent data stored in one row of a database table. If the client terminates or if the server shuts down, the underlying services ensure that the entity bean data is saved.

message-driven bean combines features of a session bean and a Java Message Service ("JMS") message listener, allowing a business component to receive JMS messages asynchronously. This tutorial describes entity beans and session beans. For information on message-driven beans, see The Java Message Service Tutorial, available at

http://java.sun.com/products/jms/tutorial/index.html 


Enterprise Information System Tier


The enterprise information system tier handles enterprise information system software and includes enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems. J2EE application components might need access to enterprise information systems for database connectivity, for example.

J2EE Tutorial-2 (Distributed Multitiered Applications)

The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs. Figure 1-1 shows two multitiered J2EE applications divided into the tiers described in the following list. The J2EE application parts shown in Figure 1-1 are presented in J2EE Components.Client-tier components run on the client machine.

Web-tier components run on the J2EE server.

  • Client-tier components run on the client machine.

  • Web-tier components run on the J2EE server.

  • Business-tier components run on the J2EE server.

  • Enterprise information system (EIS)-tier software runs on the EIS server.


Although a J2EE application can consist of the three or four tiers shown in Figure 1-1, J2EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three different locations: client machines, the J2EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage.



Figure 1-1 Multitiered Applications

J2EE Tutorial -1 (overview)

Today, more and more developers want to write distributed transactional applications for the enterprise and leverage the speed, security, and reliability of server-side technology. If you are already working in this area, you know that in today's fast-moving and demanding world of e-commerce and information technology, enterprise applications have to be designed, built, and produced for less money, with greater speed, and with fewer resources than ever before.

To reduce costs and fast-track enterprise application design and development, the Java 2 Platform, Enterprise Edition (J2EE) technology provides a component-based approach to the design, development, assembly, and deployment of enterprise applications. The J2EE platform offers a multitiered distributed application model, the ability to reuse components, integrated Extensible Markup Language (XML)-based data interchange, a unified security model, and flexible transaction control. Not only can you deliver innovative customer solutions to market faster than ever, but your platform-independent J2EE component-based solutions are not tied to the products and application programming interfaces (APIs) of any one vendor. Vendors and customers enjoy the freedom to choose the products and components that best meet their business and technological requirements.

This tutorial takes an examples-based approach to describing the features and functionalities available in J2EE Software Development Kit (SDK) version 1.3. Whether you are a new or an experienced enterprise developer, you should find the examples and accompanying text a valuable and accessible knowledge base for creating your own enterprise solutions.

If you are new to J2EE applications development, this chapter is a good place to start. Here you will learn the J2EE architecture, become acquainted with important terms and concepts, and find out how to approach J2EE application programming, assembly, and deployment.