Java and J2EE:


Browser<-->Web-Container Communication

The containers are J2EE runtime environments that provide required low-level, platform-specific services to the application components

  1. When the Web server receives the input, it passes the request to the servlet.
  2. The servlet then calls a method for action.
  3. When the servlet receives the results  it returns the calculated value to the end user in an HTML page, using the response object passed by the Web server.
  4. The servlet is bundled with its HTML file into a Web Archive (WAR) file, called as Web modules.
  5. The WAR module will be added to the J2EE application and bundled into an Enterprise Archive (EAR) file.
  6. Writing the servlet is a developer function, while creating a J2EE application and adding J2EE components is an application assembly function.
  7. HTML page that accepts the input.
  8. Create the Servlet: for processing and dynamic contents.
    1. import Declarations: J2EE classes/interfaces:
    • javax.servlet.ServletException: The HttpServlet classes use this class to indicate a servlet problem.
    • javax.servlet.ServletConfig: This class encapsulates the configuration information about a Servlet.
    • javax.servlet.http.HttpServlet: Every HTTP servlet suitable for a Web site should subclass this abstract class.
    • javax.servlet.http.HttpServletRequest: This interface provides the request information for HTTP servlets.
    • javax.servlet.http.HttpServletResponse: This interface provides HTTP-specific functionality in sending a response to a request.
    • The HttpServlet classes use the IOException class to signal that an input or output exception of some kind has occurred.
    • The Servlet classes use this class to write the response data.

        init Method: 

    • This method is called by the servlet container.
    • Input parameter : Servlet configuration information (as ServletConfig).

    doGet Method

    • takes a HttpServletRequest and HttpServletResponse object.
      • HttpServletRequest :information that the browser sent is captured.
      • HttpServletResponse: used to create an HTML page in response to the browser's request.
    • The doGet method throws an IOException if there is an input or output problem

    destroy Method:

    • This method will be called by the servlet container when this servlet is released from service
  9. Compile the Servlet.
  10. J2EE Application Server: 
    1. J2EE application server to deploy and run the Application.
    2. Deployment Tool: J2EE applications and their components

      1. Create J2EE Application
        1. to assemble J2EE components into a J2EE application Enterprise Archive (EAR) file:
        2. JAR file and J2EE application, and provides runtime information about the application.
        3. Create the Web Component:

          1. Web components (Java servlets and associated classes, JavaServer Pages, HTML pages, and other relevant Web resources like images) are bundled into a Web Archive (WAR) file.
  11. Specify the Root Context:

    You have to specify a context root directory where the Deployment tool will put the Web components.

    Context Root Directory Structure:

        Directory Structure
  12. Verify and Deploy the J2EE Application

  13. Run the J2EE Application

Multitiered Architecture: 4 Tier:




Container-managed persistence is the term used to describe the situation where the container handles data storage and retrieval.


JDBC Technology and Bean-Managed Persistence:

Override the default container-managed persistence and implement bean-managed persistence (BMP).

 BMP can be useful if you need to improve performance or map data in multiple beans to one row in a database table.

Bean Lifecycle:

J2EE Standards and Application Servers:

J2EE is a platform for developing distributed enterprise applications using the Java programming language.

J2EE application server, Web server, database, J2EE APIs.

Development and Deployment tools.

Core Java:

Objects and  Data Objects:

All the classes in the java.lang package are available to your programs automatically.

Character data :

Numeric data: number classes:

Arrays are implicit extensions of the Object class

The Life Cycle of an Object:

Once an object has completed the work for which it was created, it is garbage-collected and its resources are recycled for use by other objects.

Creating Objects: you create an object from a class

Example: Point origin_one = new Point(23, 94);

Declaring a Variable to Refer to an Object.

Use the object.

The Garbage Collector: 

The Java runtime environment has a garbage collector that periodically frees the memory used by objects that are no longer referenced.


Before an object gets garbage-collected, the garbage collector gives the object an opportunity to clean up after itself through a call to the object's finalize method.

Creating Classes:

Write the classes from which objects are created:

The Class Declaration:

By default, a class can be used only by other classes in the same package. The public modifier declares that the class can be used by any class regardless of its package.
Declares that the class cannot be instantiated..
Declares that the class cannot be subclassed.
class NameOfClass
The class keyword indicates to the compiler that this is a class declaration and that the name of the class is NameOfClass.
extends Super
The extends clause identifies Super as the superclass of the class, thereby inserting the class within the class hierarchy.
Variables and methods collectively are called members.

Declaring Member Variables

The transient marker is not fully specified by The Java Language Specification but is used in object serialization.
The volatile keyword is used to prevent the compiler from performing certain optimizations on a member.

Implementing Methods

Method declaration:

returnType methodName() {
    . . .
If you have a significant library of functions written in another language such as C, you may wish to preserve that investment and use those functions from Java.
Concurrently running threads often invoke methods that operate on the same data. These methods may be declared synchronized to ensure that the threads access information in a thread-safe manner.
Click to go to  Home Page