J2EE Overview: Ian Cole Orlando Java User's Group February 28, 2002
J2EE Overview: Ian Cole Orlando Java User's Group February 28, 2002
J2EE Overview: Ian Cole Orlando Java User's Group February 28, 2002
Ian Cole
Orlando Java User’s Group
February 28, 2002
Presentation Overview
Introductionto J2EE
Explain the major technologies within
the J2EE designation
J2EE applications
J2EE servers
The Java 2 Platform
Platform introduced June, 1999
J2SE – Java 2 Standard Edition
Java for the desktop / workstation
http://java.sun.com/j2se
J2ME – Java 2 Micro Edition
Java for the consumer device
http://java.sun.com/j2me
J2EE - Java 2 Enterprise Edition
Java for the server
http://java.sun.com/j2ee
The Java 2 Platform
http://java.sun.com/java2/
J2EE Technologies
Java Servlets
JSP
EJB
JMS
JDBC
JNDI
JTA / JTS
JavaMail
JAAS
XML
…
J2EE Components
http://java.sun.com/j2ee/overview3.html
Java Servlets
Servlets are the Java platform technology of
choice for extending and enhancing web servers.
Servlets provide a component-based, platform-
independent method for building web-based
applications, without the performance limitations
of CGI programs.
http://java.sun.com/products/servlets/index.html
Java Servlets
Servlets have access to the entire family of Java
APIs, including the JDBCTM API to access enterprise
databases.
Servlets can also access a library of HTTP-specific
calls and receive all the benefits of the mature
Java language, including portability, performance,
reusability, and crash protection
http://java.sun.com/products/servlets/index.html
Anatomy of a Servlet
init() – the init() function is called when the servlet is
initialized by the server. This often happens on the
first doGet() or doPut() call of the servlet.
destroy() – this function is called when the servlet is
being destroyed by the server, typically when the
server process is being stopped.
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.html
Anatomy of a Servlet
doGet() – the doGet() function is called when the
servlet is called via an HTTP GET.
doPost() – the doPost() function is called when the
servlet is called via an HTTP POST.
POSTs are a good way to get input from HTML forms
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.html
Anatomy of a Servlet
HTTPServletRequest object
Information about an HTTP request
Headers
Query String
Session
Cookies
HTTPServletResponse object
Used for formatting an HTTP response
Headers
Status codes
Cookies
Sample Servlet
import java.io.*; //Apache Tomcat sample code
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
JSP – JavaServer Pages
JavaServer Pages technology uses XML-like tags and
scriptlets written in the Java programming language to
encapsulate the logic that generates the content for
the page.
Any and all formatting (HTML or XML) tags are
passed directly back to the response page.
By separating the page logic from its design and
display and supporting a reusable component-based
design, JSP technology makes it faster and easier
than ever to build web-based applications.
http://java.sun.com/products/jsp/index.html
Sample JSP
<html> <!- Apache Tomcat Samples ->
<!-- Copyright (c) 1999 The Apache Software Foundation. All rights reserved.-->
<body bgcolor="white">
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<font size=4><ul>
<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
<li> Year: is <jsp:getProperty name="clock" property="year"/>
<li> Month: is <jsp:getProperty name="clock" property="month"/>
<li> Time: is <jsp:getProperty name="clock" property="time"/>
<li> Date: is <jsp:getProperty name="clock" property="date"/>
<li> Day: is <jsp:getProperty name="clock" property="day"/>
<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
<li> era: is <jsp:getProperty name="clock" property="era"/>
<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
</ul>
</font>
</body>
</html>
EJB – Enterprise Java Beans
Enterprise JavaBeansTM is the server-side
component architecture for the J2EETM platform.
EJBTM enables rapid and simplified
development of distributed, transactional,
secure and portable Java applications.
Current Specification: 2.0 – 4/16/2001
http://java.sun.com/products/ejb/index.html
EJB – Enterprise Java Beans
Enterprise Java Beans are components that
are deployed into containers
The container provides services
Loading / Initialization
Transactions
Persistence
Communication with EJB clients
Enterprise Naming Context (JNDI name space)
Anatomy of an EJB
Remote Interface
Methods that can be accessed by the outside world.
Extends javax.ejb.EJBObject
Remote Home Interface
Life-cycle methods (create, findByPrimaryKey)
Extends javax.ejb.EJBHome which extends
java.rmi.Remote
Bean class
The class performing the actual business process
Implements an interface based on type of bean
Anatomy of an EJB
EJB 2.0 New Interfaces
New Interfaces allow bean to bean method
calls within the same container
Local Interface
Similar to the remote interface, but without RMI
Extends javax.ejb.EJBLocalObject
/** This interface defines the `Remote' interface for the `Interest' EJB. Its single method is the only
method exposed to the outside world. The class InterestBean implements the method. */
/** This interface defines the 'home' interface for the 'Interest' EJB. */
public interface InterestHome extends EJBHome
{
/** Creates an instance of the `InterestBean' class on the server, and returns a remote reference to an
Interest interface on the client. */
/** This class contains the implementation for the 'calculateCompoundInterest' method exposed by this
Bean. It includes empty method bodies for the methods prescribe by the SessionBean interface; these
don't need to do anything in this simple example. */
<ejb-jar>
<description>JBoss Interest Sample Application</description>
<display-name>Interest EJB</display-name>
<enterprise-beans>
<session>
<ejb-name>Interest</ejb-name>
<home>org.jboss.docs.interest.InterestHome</home>
<remote>org.jboss.docs.interest.Interest</remote>
<ejb-class>org.jboss.docs.interest.InterestBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
EJB – Session Bean Example
package org.jboss.docs.interest;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
class InterestClient
{
/** This method does all the work. It creates an instance of the Interest EJB on the EJB server, and calls its
`calculateCompoundInterest()' method, then prints the result of the calculation. */
Interest interest = home.create(); //Create an Interest object from the Home interface
JMS Topic
JMS – Java Message Service
The JMS API in the J2EE 1.3 platform has the
following new features:
A new kind of enterprise bean, the message-driven bean,
enables the asynchronous consumption of messages.
Message sends and receives can participate in
Java Transaction API (JTA) transactions.
http://java.sun.com/products/jms/index.html
JMS – Java Message Service
Why should I use JMS?
Loosely-coupled systems
Connectionless
Removes dependence on client and server platform /
programming language / version
Publish / Subscribe metaphor
Send / receive information with many, unknown clients
Integration with other messaging systems
IBM MQ-Series
Microsoft Message Queue
http://java.sun.com/products/jms/index.html
JDBC – Data Access API
JDBCTM technology is an API that lets you access
virtually any tabular data source from the JavaTM
programming language.
Cross-DBMS connectivity to a wide range of SQL
databases
Access to other tabular data sources, such as
spreadsheets or flat files.
http://java.sun.com/products/jdbc/index.html
JDBC – Driver Types
Level 1 - A JDBC-ODBC bridge provides JDBC API
access via one or more ODBC drivers.
Level 2 - A native-API partly Java technology-
enabled driver converts JDBC calls into calls on the
client API for Oracle, Sybase, Informix, DB2, or
other DBMS.
Level 3 - A net-protocol fully Java technology-
enabled driver translates JDBC API calls into a
DBMS-independent net protocol which is then
translated to a DBMS protocol by a server.
Level 4 - A native-protocol fully Java technology-
enabled driver converts JDBC technology calls into
the network protocol used by DBMSs directly.
http://java.sun.com/products/jdbc/driverdesc.html
JNDI – Java Naming and
Directory Interface
JNDI is an API specified in Javatm that provides naming and
directory functionality to applications written in Java. It is
designed especially for Java by using Java's object model.
Using JNDI, Java applications can store and retrieve named
Java objects of any type.
JNDI provides methods for performing standard directory
operations, such as associating attributes with objects and
searching for objects using their attributes.
JNDI allows Java applications to take advantage of information
in a variety of existing naming and directory services, such as
LDAP, NDS, DNS, and NIS(YP), and allows Java applications to
coexist with legacy applications and systems.
http://java.sun.com/products/jndi/overview.html
JNDI - Layers
JNDI – Common Uses
JNDI ENC – “enterprise naming context”
EJB lookup within a J2EE app server
LDAP integration
Dynamic registration of services and clients
Peer to Peer computing
JNDI – Session Bean Example
package org.jboss.docs.interest;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
class InterestClient
{
/** This method does all the work. It creates an instance of the Interest EJB on the EJB server, and calls its
`calculateCompoundInterest()' method, then prints the result of the calculation. */
Interest interest = home.create(); //Create an Interest object from the Home interface
http://java.sun.com/j2ee/transactions.html
JavaMail
The JavaMailTM 1.2 API provides a set of abstract classes that
model a mail system.
The API provides a platform independent and protocol
independent framework to build Java technology-based mail and
messaging applications.
J2EE contains JAF – JavaBeans Activation Framework since it
is required by JavaMail
Supports common mail protocols
IMAP
POP
SMTP
MIME
http://java.sun.com/products/javamail/index.html
JAAS – Java Authentication
and Authorization Service
Authentication of users, to reliably and securely determine
who is currently executing Java code, regardless of whether
the code is running as an application, an applet, a bean, or a
servlet; and
Authorization of users to ensure they have the access control
rights (permissions) required to do the actions performed.
Sample authentication modules using:
JavaTM Naming and Directory Interface (JNDI)
Unix Operating Environment
Windows NT
Kerberos
Keystore
http://java.sun.com/products/jaas/index.html
XML
J2EE 1.3 includes JAXP 1.1 support, as well
as Servlet Filters and XML JSPTM documents.
The JavaTM API for XML Processing ("JAXP")
supports processing of XML documents using
DOM, SAX, and XSLT.
The portability and extensibility of both XML
and Java make them the ideal choice for the
flexibility and wide availability requirements of
this new web.
http://java.sun.com/xml/index.html
http://java.sun.com/xml/jaxp/index.html
J2EE Connectors
The J2EE Connector architecture defines a standard architecture for connecting
the J2EE platform to heterogeneous EISs (Enterprise Information Systems).
Examples of EISs include ERP, mainframe transaction processing, database
systems, and legacy applications not written in the Java programming language.
http://java.sun.com/j2ee/connector/index.html
J2EE Applications
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Oveview3.html
J2EE Deployment
JAR – Java ARchive
Java class file
EJBs
WAR - Web ARchive
Servlets
JSPs
EAR - Enterprise ARchive
Contains other JARs and WARs to form an entire application
Deployment descriptors
XML
Required for EJB JARs, WARs, EARs
J2EE Servers
Application Server
As of Sept ’01 - MetaGroup Survey by sales $$
BEA Weblogic - 37%
IBM Websphere – 22%
Oracle – 11%
Iplanet – 5%
Other- 12%
Open-source
Jboss – www.jboss.org
Sun’s listing of J2EE compatible servers -
http://java.sun.com/j2ee/compatibility.html
J2EE Servers
Servlet / JSP Servers
Most of the commercial application servers
also include servlet / JSP support
Open-Source
Apache Tomcat
Jetty