Title: JAVA TECHNOLOGY
1JAVA TECHNOLOGY
- PRESENTED BY
- KOTESWARA RAO KOMMINENI
2TOPICS
- SERVLETS
- JDBC
- RMI
- JavaIDL
- JMS
3SERVLETS
4Servlets
- Introduction
- Why do we need Servlets?
- Working of a Servlet
- Servlet API
- Example
- Job of a HTTP Servlet
5Introduction
- What is a servlet?
- Server side extension of a web server.
- Dynamically loaded Java class.
- Provide a component-based, platform independent
method for building web-based applications
without performance limitations of CGI. -
6Why do we need Servlets?
- Efficient
- Uses light weight java thread to handle a
request. - Single copy of servlet processes N requests from
the client. - They remain active even after response.
- Convenient
- Provides infrastructure for automatic parsing and
decoding HTML form data, reading and setting HTTP
headers, tracking sessions etc. - Powerful
- Can talk directly to the web server.
- Makes it easier to translate relative URLs into
concrete path names. - Multiple servlets can also share data by making
it easy to implement database connection pooling. - Portable
- Secure
- Inexpensive
7Working of a Servlet
8Servlet API
- Java Provides two packages for developing
Servlets. - Package javax.servlet
- Package javax.servlet.http
- Two types of Servlets
- Temporary
- Permanent
- Web server communicates with a servlet through a
simple interface, javax.servlet.Servlet. This
interface consists of three main methods - init()
- service()
- destroy()
9Example Servlet
- import java.io.
- import javax.servlet.
- public class SampleServlet extends Servlet
-
- private ServletConfig config
- public void init(ServletConfig config)
- throws ServletException
- this.configconfig
-
- public void destroy()
-
- public ServletConfig getServletConfig()
-
- return config
-
- public String getServletInfo()
-
- return A Simple Servlet
10Example Servlet(cont)
- public void service(ServletRequest
req,ServletResponse res) - throws ServletException, IOException
-
- res.setContentType(text/html)
- PrintWriter outres.getWriter()
- out.println(lthtmlgt)
- out.println(ltheadgt)
- out.println(lttitlegt A Sample Servletlt/titlegt)
- out.println(lt/headgt)
- out.println(lth1gtA Sample Server lt/h1gt)
- out.println(lt/bodygt)
- out.println(lt/htmlgt)
- out.close()
-
11Job of a HTTP Servlet
- Read any data sent by the user.
- Look up any other information about the request
that is embedded in the HTTP request. - Generate the results.
- Format the results inside a document.
- Set the appropriate HTTP response parameters.
- Send the document back to the client.
12JAVA DATABASE CONNECTIVITY
13JDBC API
- JDBC is a Java API that provides universal data
access for the java programming language. - It supports standard way to access
object-relational features supported by todays
relational database management systems. - It provides connection pooling mechanism with
server.
14JDBC API VERSUS ODBC
- Why do we need JDBC?
-
- ODBC uses a C interface.
- Translation of ODBC C API into a Java API is not
desirable. - ODBC is hard to learn.
- To develop a pure java solution.
15Basic Steps in Using JDBC
- There are seven standard steps in querying
databases - Load the JDBC Driver.
- Define the connection URL.
- Establish the connection.
- Create a Statement object.
- Execute a query.
- Process the results.
- Close the connection.
16Load the JDBC Driver
- try
-
- Class.forName(connect.microsoft.MicrosoftDriver)
- Class.forName(oracle.jdbc.driver.OracleDriver)
- Class.forName(com.sybase.jdbc.SybDriver)
-
- catch(ClassNotFoundException cnfe)
-
- System.out.println(Error Loading Driver
cnfe)
17Define the connection URL
- String host dbhost.yourcompany.com
- String dbnamesomeName
- int port1234
- String oracleURLjdbcoraclethin_at_hostpor
tdbname - String
- sybaseURLjdbcsybaseTdshostport?S
ERVICENAMEdbname
18Establish the connection
- String usernamejay_debesee
- String passwordsecret
- Connection connectionDriverManager.getConnection(
oracleURL,username,password)
19Create a Statement
- Statement statementconnection.CreateStatement()
Execute a Query
String querySELECT col1,col2,col3 FROM
sometable ResultSet resultsetstatement.executeQ
uery(query)
20Process the Results
- while(resultset.next())
-
- int xresultset.getInt(col1)
- String sresultset.getString(col2)
- float fresultset.getFloat(col3)
Close the Connection
connection.close()
21Prepared Statements (Precompiled Queries)
- Connection connectionDriverManager.getConnection(
url,username,password) - String templateUPDATE employees SET SALSAL ?
WHERE EID?
22CONNECTION POOLING
- What is connection pooling?
- A Connection Pool class should be able to do the
following tasks - Preallocate the connections.
- Manage available connections.
- Allocate New Connections.
- Wait for a connection to become available.
- Close connections when required.
23Preallocate the Connections
- availableConnections new Vector(initialConnection
s) - busyConnectionsnew Vector()
- for(int i0iltinitialConnectionsi)
-
- availableConnections.addElement(makeNewConnection(
))
24Application Development Using JDBC
- Two types of Application models
- Two-tier Application Model
- Three-tier Application Mode.
25Two-tier Application Design
Client
JDBC Driver
TCP/IP socket
Database
- Simple Design
- Used for developing small applications
26Three-tier Application Design
Middle Tier
JDBC Driver
Client
TCP/IP socket
RMI/CORBA
Database
- Preferred Design.
- Additional benefits from middle tier
- Isolation of business/application logic
- Provision of simple API
- Integration of several database systems.
27Three-Tier Design Advantages
- Data Validation moves to the middle tier.
- Client can access multiple databases through a
single socket connection. - Protocol between client and middle-tier is
DBMS-independent. - Has Control over access and the kinds of updates
that can be made to the database.
28REMOTE METHOD INVOCATION(RMI)
29RMI Architecture Overview
Java RMI Client
Java RMI Server
RMI System
Stubs
Skeletons
Remote Reference Layer
Remote Reference Layer
Transport
Transport
30RMI Architecture
- RMI Architecture consists of four layers
- Application
- Stub/Skeleton
- Remote reference
- Transport
31RMI
Registry
RMI
Client
RMI
RMI
Server
URL protocol
URL protocol
Web Server
URL protocol
Web Server
32Application Layer
- Consists of actual implementation of the client
and the server applications. - Remote methods are described in an interface.
- Remote object implements the remote methods.
- Server creates servant instances and informs
registry. - Client looks up in the server registry and call
the remote methods.
33Stub and Skeleton Layer
- Is an interface between an application layer and
the remaining RMI system. - Transmits data to the remote reference layer.
- Client invoking a method use a stub.
- A skeleton is a server side entity.
34Remote Reference Layer
- Carries out semantics of method invocation.
- Manages communications between stub/skeleton and
lower-level transport interface. - Manages references to objects.
- Manages reconnection strategies.
- Includes client and server side components.
35Transport Layer
- Is responsible for
- Setting up connection and management
- Tracking and dispatching remote objects
- Performs the following tasks
- Receives request from RRL on client
- Locates RMI server
- Establishes socket connection
- Passes connection to RRL on client
- Adds object to table of remote objects
- Monitors connection
36RMI Naming Service
- Enables remote objects to be retrieved and
registered. - Has simple names for remote objects.
- Has URL-based lookup mechanism.
- rmi//hostport/name
37Creating Distributed Applications Using RMI
- General Steps involved are
- Design and Implement the application components.
- Defining the remote interfaces.
- Implementing the remote objects.
- Implementing the clients.
- Compile sources and generate stubs.
- Make classes network accessible.
- Start the application.
38JavaIDL
39JavaIDL
- It is a technology for distributed objects.
- Enables objects to interact regardless of the
language in which they are developed. - Uses CORBA technology.
- It provides ORB( a class library that supports
interaction between objects in separate
programs).
40Java IDL Development Process
- Define the Remote Interface.
- Compile the remote interface.
- Implement the Server.
- Implement the Client.
- Start the applications.
41RMI vs. JavaIDL
- From the development points of views
- There are three types of developers
- CORBA veterans.
- Java purists.
- Novice developers.
42RMI vs. CORBA
- Advantages of CORBA
- No Special language requirements.
- Interfaces between clients and servers are
defined in IDL. - Standardized services like Naming and Event
Service. - Dynamic method discovery and invocation.
43RMI vs. CORBA
- Disadvantages of CORBA
- Do not support pass by value.
- Cannot allow a type-safe object passing.
- It is mandatory that both sides know in advance
exactly what object will be passed. - Support for heterogeneous systems.
44RMI vs. CORBA
- Advantages of RMI
- Invoke methods as if they were local.
- Uses optimized protocol. Data marshalling is
handled transparently for the developer. - Java Objects in different VMs can transparently
invoke each others methods. - Enables garbage collection of inactive objects.
- parameters cab be passed both by reference as
well as by value.
45RMI vs. CORBA
- Disadvantages of RMI
- Pure Java Solution.
- No event support is provided in RMI.
- RMI naming service is primitive.
- Uses TCP/IP instead of IIOP.
46JMS API
47JAVA MESSAGE SERVICE
- What is Messaging?
- What is JMS API?
- When to Use JMS API?
- How JMS API works with J2EE?
- JMS API Architecture
- Messaging Domains
- Message Consumption
48- Messaging
- Messaging is the method of communication between
the software components. - What is JMS API ?
- JMS is a Java API that allows applications to
create, send, receive and read messages. It
enables not only loosely coupled messaging but
also supports Asynchronous and Reliable
communication.
49When to Use JMS API?
- Provider wants the components not to depend on
information about other interfaces, so that
components can be easily replaced. - Provider wants the application to run whether or
not all components are up and running
simultaneously. - The application business model allows a component
to send information to another and continue to
operate without receiving an immediate response.
50How JMS works with J2EE?
- JMS API of J2EE platform has the following
features - Application Clients, EJB components and web
components can send or synchronously receive a
JMS message. - A new kind of EJB, the Message-Driven Bean,
enables asynchronous consumption of messages. - Message sends and receives can participate in
distributed transactions.
51JMS API Architecture
- JMS Provider
- JMS Clients
- Messages
- Administered Objects
52JMS API ARCHITECTURE
JNDI Namespace
CF
Bind
Administrative Tool
D
Lookup
JMS Client
JMS Provider
Logical Connection
53Messaging Domains
- Before JMS Existed
- Point to Point(PTP)
- Publish/Subscribe(pub/sub)
- JMS API Provides separate domain for each
approach - JMS Provides both the domains.
- Some clients use both the domains in same
application.
54Point to Point Messaging Domains
Msg
Client 2
Msg
Client 1
Queue
Consumes
Sends
Acknowledges
55Point-to-Point Messaging Domain
- Characteristics of Point-to-Point Messaging
Domain - Only one consumer for each Message.
- No time Dependencies.
- Receiver Acknowledges.
- When to use this Domain?
- When every message that is sent must be
successfully processed by one consumer.
56Publish/Subscribe Messaging Domain
Topic
Client 2
Subscribes
Msg
Delivers
Client 1
Msg
Client 3
Publishes
Subscribes
Delivers
Msg
57Publish/Subscribe Messaging Domain
- Characteristics of Publish/Subscribe Messaging
Domain - Multiple Consumers.
- Time Dependency.
- No Receiver Acknowledgements.
- When to use this Domain?
- When each message that is sent must be processed
by zero, one or more consumers.
58Building Blocks of JMS client Application
- Administered Objects Connection factories and
Destinations - Connections
- Sessions
- Message Producers
- Message Consumers
- Messages
59JMS API Programming Model
Connection Factory
Creates
Connection
Creates
Message Consumer
Session
Message Producer
Creates
Creates
Receives From
Sends To
Creates
Destination
Destination
Msg
60References
- http//java.sun.com/docs/books/tutorial/rmi/index.
html - http//java.sun.com/j2se/1.4.1/docs/guide/jdbc/get
start/intro.html1018464 - http//csajsp-chapters.corewebprogramming.com/CSAJ
SP-Chapter18.pdf - http//java.sun.com/docs/books/tutorial/idl/summar
y/index.html - http//www.javaworld.com/javaworld/jw-01-2000/jw-0
1-howto.html - http//www.weblogic.com/docs45/classdocs/API_jndi.
htmldistributed - http//developer.java.sun.com/developer/onlineTrai
ning/Servlets/Fundamentals/servlets.html - http//java.sun.com/products/servlet/articles/tuto
rial/ - www.acm.org