J2EE by stariya


									J2EE(Java 2 Enterprise Edition)
           Java 2 Enterprise Edition is comprised of three major areas:

              Components-The J2EE platform supports four types of
               components: Application, Applet, Web, and Enterprise Java
              Containers-Providing J2EE services such as security, transaction
               management, and resource pooling.
              Services-The J2EE platform specifies standard services. Some
               of these are: HTTP, Java Beans Activation Framework, Java
               IDL, Java Mail, Java Messaging Services, Java Naming and
               Directory Interface, Java Transaction API, JDBC, Resource
               Manager Drivers, and RMI-IIOP.


The J2EE platform supports four types of components:

Application : Standalone applications that run directly on a workstation.

Applet : Run within a Web browser.

Web : Consist of Servlets and Java Server Pages and execute on a Web
server in response to HTTP requests from a Web browser. Servlets are small
Java programs that run on the server. Servlets extend the processing
capability of the Web server. Servlets also enable dynamic Web pages by the
use of server-side includes and JSP. Java Server Pages contain embedded
server-side scripts. The Web server ensures that this script is processed and
the results are sent to the client.

Enterprise Java Bean (EJB) : The primary building blocks for assembling
applications and provide a standard architecture for developing and sharing
components. EJBs execute on a separate server and contain the business
logic, or process, for the application.


provide an environment for components to run in. The container approach enables
you, as the developer, to focus on developing the application, while the Java
enterprise architecture provides the J2EE services automatically and
transparently. These J2EE services might include security, transaction
management, and resource pooling.

What role does the container play in the J2EE architecture?

      It insulates the component from the service.
      It enables a component to access different services at different
    times, without modifications to the component.
The J2EE architecture specifies a set of standard services. The services
included are:

              HTTP : These are services accessed through the HTTP client-
               side API provided in the java.net package, and through the
               HTTP server-side API provided in the Servlet and JSP
              Java Beans Activation Framework (JAF) : This service is used
               by the JavaMail API.
              Java IDL : This service enables application components to
               invoke external CORBA objects using the IIOP protocol.
              Java Mail : A service that sends Internet mail.
              Java Messaging Services (JMS) : Messaging enables
               asynchronous communications between program components.
               Message orientation provides a degree of independence
               between the program components and is critical to achieving
               high scalability. JMS supports reliable point-to-point messaging
               and the publish-subscribe model.
              Java Naming and Directory Interface (JNDI) : The Internet has
               many independent nodes that you access with a name and an
               address. The standard JNDI APIs provide you with a single API
               to access directory and naming services such as the Domain
               Name Service (DNS) and your local file-management system.
              Java Transaction API (JTA) : This service provides transaction
               processing services to assure integrity of database operations.
              JDBC : Java Database Connectivity (JDBC) is a set of standard
               APIs to establish connectivity and to interact with relational
               databases and with other data sources. Besides providing a
               standard API to access databases, it defines a standard
               architecture for the database manufacturers to build standard
               drivers to access their database.
              Resource Manager Drivers : These drivers extend the power of
               the J2EE by implementing network connectivity to an external
               resource manager.
              RMI-IIOP : Applications use Remote Method Invocation (RMI) to
               establish network connections transparently in order to invoke
               methods remotely. RMI provides a transparent pipe-like link
               between the application and the remote method. Applications
               are required to use RMI-IIOP API's to access EJB components.

Why is a multi-tier approach important?

Multi-tier approach is important because of performance, scalability, security, and
A Uniform Resource Locator (URL) is an address for a resource on the
network, usually a file name or document name. The general syntax for a URL
is as follows:


In this course, you will be using the HTTP protocol. Example:



HyperText Transfer Protocol (HTTP) is a simple, small, and fast I/O protocol that is
currently the primary protocol on the World Wide Web (WWW). HTTP uses URLs to
identify resources. The default port assigned to HTTP by TCP/IP is port 80.

HTTP is a simple protocol with only seven commands. These seven commands
are summarized in the table shown.

          Command           Description
          DELETE            Request tells the server to delete a URL resource.
          GET               Retrieves a resource and sends it to the client.
          HEAD              Gets information about the URL and not the resource itself.
          LINK              Links a URL with specific resources.
          POST              The client sends data to the server.
          PUT               The client sends data to the server.
          ULINK             Unlinks a URL from specific resources.

What is the flow of document and control on the World Wide Web when a simple web
page is opened?

1.     The client sends the request to the server.
2.     The Internet gets IP addresses from DNS servers if necessary.
3.     Server locates the resource.
4.     Server sends response document.
5.     Client displays or renders the response document in the
What is the flow of document and control on the World Wide Web when a
document that contains an image?

1.     The client sends request to the server.
2.     Internet gets IP addresses from DNS servers if necessary.
3.     Server locates resource.
4.     Server sends response document.
5.     Clients displays the response in browser.
6.     Browser finds an image tag.
7.     Browser requests image tag.
8.     Internet gets IP addresses from DNS servers if necessary.
9.     Server locates resource.
10.    Server sends response document.
11.    Clients renders image in browser.

Program Units and Files in J2EE

An Application

An application is a standalone program that can run directly on the operating
system (OS) of your computer. You do not need a browser or an HTML file to
invoke the application. An application is similar to the type you can build
using C++, Pascal, and Basic. It requires a Java Virtual Machine (JVM)
emulator on which to run.

An Applet

An applet is a special kind of application that can be invoked by an HTML
<APPLET> tag running in a browser. It can be downloaded across the
Internet (just as you would an image or a multimedia file), and then run in
the context of the browser. An applet has to be invoked by an <APPLET> tag
running within a browser. It requires a Java Virtual Machine (JVM) emulator
on which to run.

What is the difference between an application and an applet?

An application is a standalone program that can run in the operating system of
your computer. An applet needs to be invoked. It runs in the Web browser or
applet viewer. In either case, a JVM is needed.

What is the difference between an applet and a Servlet?

The applet runs in a browser, the Servlet runs in a server.
The Java Server Page (JSP)

A Java Server Page is an HTML text document that contains a kind of
embedded scripting language that is a subset of the Java language. JSP
documents can themselves be request documents, or they can respond to
request documents. The file extension for the Java Server Page is .jsp.

A Servlet

The Java Servlet is a bytecode file specifically developed to be a Servlet
component. Running on the server, it functions as a kind of bridge between
the HTML world and the Java world. You first create the source file that
extends HttpServlet and then compile it, producing the bytecode, or class
file. The extension of the source file is .java , and the file extension of the
Servlet is .class .

A CGI Script

A CGI script uses CGI/Perl script to specify server-side scripting. The file
extension is .pl .

The Java Source File (.java)
The source file is the file into which you enter instructions using the Java
language. The instructions you enter in the source file determine what the
application will do. The source file is what makes one application perform
differently from another. The name of the file must match, letter for letter,
the name of the class being declared within that file, and the cases must also
match. The file extension is .java . Since this file requires a four-letter
extension, you cannot run Java on older operating systems, such as Windows
3.1, due to three-character file extension limit.

The Class File (.class)
When you compile the Source file, which consists of Java statements, the
compiler produces a class file containing bytecode . Bytecode is the universal
machine language instruction set for the Java Virtual Machine (JVM). In other
words, the JVM can understand and process bytecode instructions.

The HTML File (.html)
The HTML file contains an HTML tagged page. One of the tags that HTML uses
is the <APPLET> tag. The <APPLET> tag specifies the Java applet to be
downloaded and executed (run) within the context of the browser. The file
extension for an HTML file is .htm or .html .
The Enterprise Java Bean
The enterprise java bean (EJB) is a Java component that can be deployed in a
distributed computing environment. You define the bean in a Java source file
that extends either the SessionBean or the EntityBean. You compile these
files to produce bytecode or class files. You specify the EJB using XML.

*********The file extension for the source file is .java . The file extension
for the bytecode file is .class . The file extension for the XML file is .xml.

The Text Editor
A text editor enables you to create a text file, though it will not embed any
special formatting, as traditional word processors can. The Notepad text
editor is included in a standard Windows platform.

Notepad is a very simple and straightforward text editor. It has no special
functionality such as displaying line numbers. The VI editor, on the other
hand, comes bundled with Unix systems.

The HTML Editor
In the past, you may have spent a considerable amount of time tediously
typing in HTML tags. Now you can find a number of GUI drag-and-drop
editors to do this for you such as Microsoft FrontPage, Macromedia
Dreamweaver, Adobe GoLive, and HoTMetaL.

The Appletviewer
The appletviewer is one of the building blocks packaged within the JDK. The
appletviewer enables you to test applets that have been developed with a
corresponding release level of Java. For example, if you were writing Java 1.3
code, the appletviewer that is part of the JDK 1.3 download will be able to
test all the features of level 1.3. The appletviewer ignores the display of
HTML-related tags.

The Java Web Server
The Java Web Server is a software application that can accept HTML or JSP
requests, build responses, and send those responses to the browser.

The Web Browser
Web browser is a program that allows you to navigate the World Wide Web
and to display HTML pages from these locations. Microsoft Internet Explorer
and Netscape Navigator are typical examples of Web browsers.
What is JDBC


ODBC is a standard API library that enables you to use standard calls to
access relational and non-relational databases without having to concern
yourself with the specifics of that particular database.

JDBC is Sun's solution for DBMS-independent interfaces to databases. JDBC's
architecture and philosophy is very similar to that of ODBC.

       JDBC vs. ODBC

          ODBC                                   JDBC
          ODBC API is based on the C             Java does not have all the constructs that are in
          language.                              C, such as pointers. JDBC API is adapted to the
                                                 Java language.
          ODBC drivers and managers are          JDBC drivers and managers are developed in
          developed in C++.                      Java.
          ODBC does not connect directly to      JDBC connects directly to the JDBC language.
          Java. (This is not really an ODBC
          issue, but a platform issue relating
          to Java implementation on the
          Windows platform.)
          ODBC drivers have to be installed      JDBC drivers only have to reside on the server.
          on every machine. This is not the
          case for Microsoft's OLE DB
          database-independent API.
          ODBC has been widely endorsed          JDBC is newer technology; not as widely
          and is supported by most vendors       supported.
          across the computer industry.
          ODBC supports two- and three-tier      JDBC supports two- and three-tier architectures.
          ODBC's performance is generally        JDBC's performance is generally weaker because
          better because it uses a compiled      it uses an interpreted language. This was one
          language.                              reason some people initially implemented some
                                                 components in C++.
          ODBC uses ANSI standard SQL            JDBC uses the individual DBMS vendor's
          language for data access.              implementation of the SQL language. You get
                                                 more power since you can use the extensions.
                                                 But you lose portability, since the calls that
                                                       contain these extensions will not work if you use
                                                       another DBMS.

The JDBC Concept

The java.sql package is central to the JDBC concept. It provides interfaces,
classes, and methods to enable you as a Java application developer to access
databases using JDBC calls.       There is another group of developers who
make databases accessible to Java and who must also implement interfaces
housed in java.sql. Database vendors develop a database interface to their
database. These interfaces may either be vendor-independent or vendor-
specific interfaces. Either the vendors or third-party providers develop JDBC
drivers that are wrappers of these database interfaces. These drivers
implement interfaces in the java.sql package

Why do we need JDBC when the marketplace has standardized on ODBC?

       Java does not directly interface with ODBC.
       To get away from installing ODBC drivers on every machine.

Describe the potential impact on programming in Java, if JDBC did not exist.

     You would be locked into a database.
     Extensive changes would be necessary to move to another

Identify and explain some of the pros and cons of the way SQL is
implemented in JDBC?

      JDBC does not enforce standard SQL; it passes the SQL
    statements directly to the database, so that you can use the
    extensions to SQL as implemented by that database.
      JDBC is faster, but you are locked into the database.

Describe the benefits JDBC provides programmers over ODBC.

The JDBC drivers need to only reside on the server, therefore they do not need to
be installed on every machine, as with ODBC. JDBC is DBMS – independent and it
uses the individual DBMS vendor’s implementation of the SQL language. To
program in Java without JDBC you would either be locked into a particular
database, or need to make extensive changes to move from one database to

What are the two packages in which JDBC 2.0 are provided?

The java.sql package houses the JDBC Core API in both J2SE and J2EE. Only in the
J2EE, the java.sql package holds the JDBC Standard Extension API that adds new
features that enable you to implement JDBC in a three-tier architecture, take advantage
of connection pooling, and use distributed transactions.
SQL(Structured Query Language)

Data Definition Language (DDL) is a database language that affects the structure
of the container. SQL gives you three DDL statements that affect the structure of
the database; they are:

               CREATE;
               ALTER; and
               DROP.

 The Date Manipulation Language(DML) affects the content. SQL gives four DML
statements that affect the structure of the database, SELECT, INSERT INTO, UPDATE,

The Process of builiding a JDBC application(eSLC page 11 activity is important,vg)

           steps to build a JDBC application:

           1.   Create a datasource.
           2.   Load the JDBC driver.
           3.   Identify the database URL for the DSNs      that you set up.
           4.   Open a connection to the database.
           5.   Create the statement object.
           6.   Retrieve the meta data.
           7.   Execute the SQL statement.
           8.   Process the results.
           9.   Close the connection.

2. You can invoke the Class.forName method to load a driver. The statement
to do this is:


3. The Database URL is used to identify a database. It uses the standard
JDBC notation:


Jdbc : specifies it is jdbc ; subprotocol: name of the driver ;
dataSourceName:name of the data source

           A second form of the JDBC database URL involves additional

5.JDBC statement objects are used to send SQL statements or queries to a
JDBC database and to retrieve the results of the query.

          You create a statement object by using the createStatement
          method of the connection object. The createStatement method
          returns a statement object that implements the statement
          interface. The Java code to do this is:

          Statement stmt = con.createStatement();

          The figure below shows that the annotation is:

                      Annotated syntax for creating a JDBC Statement object.

6. This is an optional step. You can find out information about the DBMS
name and version and the structure of the database.
          The connection object has a method called getMetaData, which
          enables you to get informaton about the database. The
          getMetaData method returns a DatabaseMetaData object. The
          statement to do this is:

          DatabaseMetaData dMD = con.getMetaData();

          con is the name of the connection object.

          The annotation is depicted in the figure below:

                           Annotated syntax for retrieving meta data.

7.The executeQuery method of the statement object executes the query that
you pass in a parameter. Upon completion, the executeQuery method will
return the results encapsulated within a ResultSet object.

A ResultSet object is returned when you invoke the statement object's
executeQuery method. It contains the results of the query.
The Java code to accomplish this task is:

ResultSet rs = stmt.executeQuery(sqlQuery);

sqlQuery is the SQL query you wish to execute passed in as a
String parameter.

The annotation is shown in the figure below:

            Annotated syntax for the execution of a SQL statement.
8.Process the Results

     A ResultSet object is returned when you invoke the statement
     object's executeQuery method. It contains the results of the query.

     You must use the methods of the ResultSet object that is returned
     when you execute a query and extract the data.

     You can get meta data about the data contained in the ResultSet
     object. You do this by invoking the getMetaData method of the
     ResultSet object. The code to get the ResultSet's meta data is:

     ResultSetMetaData rsmd = rs.getMetaData();

     The annotation is shown in the figure below:

                Annotated syntax for processing the results of the query.
11.Introduction to Java Server Pages (JSP)Technology

Java Server Pages (JSP), a scripting language, has become a popular
technology on the World Wide Web. Although very similar to Java, JSP
programs are easier to write than Java programs. JSP programs can run on
the server as opposed to the browser.

***********   What are Java Server Pages (JSP)?
Java Server Pages (JSP) are HTML documents embedded with a particular
scripting language that is based on the Java language. It is the only language
that can be used with JSP at this point in time. JSP documents can respond to
HTTP requests and generate dynamic Web pages.

Common Gateway Interface-The First Generation of Scripting

There are three main issues with CGI scripts:

1. It is stateless -      This means that the CGI does not keep track of data
values in previous sessions. If you wanted to preserve data between
requests, you have to send data in hidden fields that are not displayed on the
Web page. The Web developer has to develop scripts and HTML to store and
pass the state or data in hidden fields.

2. It has performance problems -          CGI scripts are interpretive. They
are processed by a Perl interpreter that has to parse the script before it can
process the commands, affecting performance.

3. The presentation and business logic functions are too tightly coupled -
CGI scripts are responsible for both generating the presentation interface and
for performing the business logic processing. This tight coupling precluded a
plug-and-play approach and made a multi-tier architecture, which would
otherwise have improved scalability, impossible. This tight coupling also
limits CGI to a two-tier architecture, an architecture that is low on

Active Server Pages (ASP)-The Second Generation of

Microsoft fielded Active Server Pages (ASP) technology that resolved many
problems with CGI. ASP are HTML text files with embedded scripts. VBScript,
JScript, or JavaScript can be used as the scripting language. Each ASP file
becomes a component in the architecture and can be initiated by any request
that has access to it. Besides, with VBScript you can access any ActiveX
component and thus enhance the quality of the processing and the interfaces.
It has one problem, however, it is a Microsoft solution and, as such, works
exclusively on Microsoft platforms.     Netscape enhances its own JavaScript
language to provide some server-side processing capabilities. This is
commonly referred to as Server-Side JavaScript.

To top