Académique Documents
Professionnel Documents
Culture Documents
By Manisha Kaushik
Manisha Kaushik
Java for the desktop / workstation http://java.sun.com/j2se Java for the consumer device http://java.sun.com/j2me
Manisha Kaushik
Java Platform, Enterprise Edition or Java EE is Oracle's enterprise java computing platform. The platform provides an API and runtime environment for developing and running enterprise software, including network and web services, and other large-scale, multi-tiered, scalable, reliable, and secure network applications. Java EE extends the Java Platform, Standard Edition (Java SE)[1], providing an API for object-relational mapping, distributed and multi-tier architectures, and web services. The platform incorporates a design based largely on modular components running on an application server. Software for Java EE is primarily developed in the Java programming language and uses XML for configuration.
Manisha Kaushik
http://java.sun.com/java2/
Manisha Kaushik
J2EE Technologies
Java Servlets JSP EJB JMS JDBC JNDI JMS JavaMail JAAS XML
Manisha Kaushik
J2EE Architecture
J2EE multi-tiered applications are generally considered to be threetiered applications because they are distributed over three different locations
client machines the J2EE server machine the database or legacy machines at the back end
Manisha Kaushik
J2EE Architecture
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
Manisha Kaushik
J2EE Containers
The application server maintains control and provides services through an interface or framework known as a container There are five defined container types in the J2EE specification
Manisha Kaushik
J2EE Containers
The server itself, which provides the J2EE runtime environment and the other two containers An EJB container to manage EJB components A Web container to manage servlets and JSP pages
An application container for stand-alone GUIs, console An applet container, meaning a browser, usually with the Java Plug-in
Manisha Kaushik
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 J2EE Components:
Client components run on the client machine, which correlate to the client containers Web components - servlets and JSP pages EJB Components - Entity Beans, Session Beans
Manisha Kaushik
Client interface files and EJB components reside in JAR files Web components reside in Web Archive (WAR) files Enterprise Archive (EAR) files represent the application, and contain all other server-side component archives that comprise the application
Manisha Kaushik
Manisha Kaushik
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
Manisha Kaushik
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.
Manisha Kaushik
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
Manisha Kaushik
Anatomy of a Servlet
HTTPServletRequest object
HTTPServletResponse object
Manisha Kaushik
Sample Servlet
import java.io.*; 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>"); } }
Manisha Kaushik
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(Common Gateway Interface) programs.
Manisha Kaushik
HTML + Java 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.
Manisha Kaushik
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>
Manisha Kaushik
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: 3.1
Manisha Kaushik
EJB Components
EJB components are server-side, modular, and reusable, comprising specific units of functionality They are similar to the Java classes we create every day, but are subject to special restrictions and must provide specific interfaces for container and client use and access We should consider using EJB components for applications that require scalability, transactional processing, or availability to multiple client types
Manisha Kaushik
Session beans
These may be either stateful or stateless and are primarily used to encapsulate business logic, carry out tasks on behalf of a client, and act as controllers or managers for other beans
Entity beans represent persistent objects or business concepts that exist beyond a specific application's lifetime; they are typically stored in a relational database
Entity beans
Manisha Kaushik
A bean's home interface specifies methods that allow the client to create, remove, and find objects of the same type The home interface provides bean management and life cycle methods EJB functionality is obtained through the bean's component interface, which defines the business methods visible to, and callable by, the client The developer writes the component interface, and the container creates the implementation for client interaction
Manisha Kaushik
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)
Manisha Kaushik
Anatomy of an EJB
Remote Interface
Bean class
Manisha Kaushik
Anatomy of an EJB
Local Interface
Similar to the remote interface, but without RMI Extends javax.ejb.EJBLocalObject Similar to the remote home interface, but without RMI Extends javax.ejb.EJBLocalHome
Manisha Kaushik
How does a client application (Java class) utilize EJBs? Lookup - JNDI ENC Network protocol - RMI EJB container creates object with RemoteHome and Home interfaces this object passes calls to the bean class
Manisha Kaushik
Manisha Kaushik
Entity beans are classes that map to individual entities typically, an Entity bean references a row in a database table, providing an object representation of that database object.
For example, an entity bean could represent a customer, and changing the values in that entity bean would cause updates to that database row
Entity beans provide an abstraction layer so that working with the entity is not specific to the storage mechanism for that entity.
Manisha Kaushik
The EJB container automatically persists the EJB objects, usually to a relational database where each type of object is represented as a table, and each instance of the object is a row in that table
The EJB container calls bean methods when it is appropriate for the bean to load, save or update data, enforcing transactions without transaction code written by the bean developer
Manisha Kaushik
For example, a session bean could charge a credit card for a specific transaction.
Manisha Kaushik
Stateful A stateful bean maintains a conversational state with a client. The client perceives that it is only talking to one bean, and that bean maintains information between calls Stateless A stateless bean maintains no client information between method calls the container can substitute beans as necessary between method calls
Manisha Kaushik
Message beans are classes that receive asynchronous notification from a Java Message Service server
For example, a message bean could be activated when vendor sends a purchase order to a JMS queue.
Manisha Kaushik
Enterprise messaging provides a reliable, flexible service for the asynchronous exchange of critical business data and events throughout an enterprise. The JMS API adds to this a common API and provider framework that enables the development of portable, message based applications in the Java programming language.
Manisha Kaushik
JMS Topic
Manisha Kaushik
Manisha Kaushik
Loosely-coupled systems
Connectionless Removes dependence on client and server platform / programming language / version Send / receive information with many, unknown clients
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.
Manisha Kaushik
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.
Manisha Kaushik
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.
Manisha Kaushik
JNDI - Layers
Manisha Kaushik
LDAP integration Dynamic registration of services and clients Peer to Peer computing
Manisha Kaushik
The Java Transaction API (JTA) and the Java Transaction Service (JTS) allow J2EE application servers to take the burden of transaction management off of the component developer. Developers can define the transactional properties of Enterprise JavaBeansTM technology based components during design or deployment using declarative statements in the deployment descriptor. The application server takes over the transaction management responsibilities.
Manisha Kaushik
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 technologybased mail and messaging applications. J2EE contains JAF JavaBeans Activation Framework since it is required by JavaMail Supports common mail protocols IMAP POP SMTP MIME
Manisha Kaushik
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
Manisha Kaushik
XML
Java EE 6 includes JAXP 1.3 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.
Manisha Kaushik
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.
Manisha Kaushik
J2EE Applications
Manisha Kaushik
Deployment Descriptors
Deployment descriptors are included in the JARs, along with component-related resources Deployment descriptors are XML documents that describe configuration and other deployment settings (remember that the Java EE application server controls many functional aspects of the services it provides) The statements in the deployment descriptor are declarative instructions to the Java EE container; for example, transactional settings are defined in the deployment descriptor and implemented by the Java EE container
Manisha Kaushik
Deployment Descriptors
Most Java EE vendors provide a GUI tool for generating deployment descriptors and performing deployment because creating manual entries is tedious and error prone The deployment descriptor for an EJB component must be named ejb-jar.xml, and it resides in the META-INF directory inside the EJB JAR file
Manisha Kaushik
Java EE Deployment
Deployment descriptors
J2EE Servers
Web Servers
Apache Tomcat Abyss web server -Abyss web server Jigsaw - The Jigsaw web server software from W3C Klone - Klone web server Lightpd - lighttpd web server Microsoft's Internet Information Services (IIS) Windows Server Oracle Web Tier - Oracle Web Tier X5 (Xitami) web server - X5 (formerly Xitami) web server Zeus web server - Zeus Technology Ltd. - Zeus web server
Manisha Kaushik
J2EE Servers
WebLogic Application Server by Oracle WebSphere Application Server from IBM Open source application servers include
JOnAS from Object Web, JBoss AS from JBoss (division of Red Hat), Geronimo from Apache, TomEE from Apache, Resin Java Application Server from Caucho Technology, Blazix from Desiderata Software, Enhydra Server from Enhydra.org, and GlassFish from Oracle.
Manisha Kaushik
Wizards for EJB / Servlets Custom editors for JSP Deployment descriptor support Deployment support for application servers Embedded servers for testing within IDE We will be using Eclipse
Manisha Kaushik