Download J2EE - WordPress.com

Document related concepts

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Clusterpoint wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Transcript
Introduction to J2EE
Dr. N. A. Joshi
Agenda
• Section A: Introduction to Java
• Evolution
• Components
• Section B: Enterprise architecture
• Types
• 2-tier, 3-tier, n-tier
• Goals of enterprise applications
• Introduction to J2EE Platform
•
•
•
•
Features
J2EE5 APIs
Architecture
Java EE Containers; & Container architecture
Section A: Introduction to Java
Introduction to Java
• Platform-independent programming language
• Used to create
• robust and secure applications, which can run on
• single computer or can be distributed among servers and clients
• 4 aspects of Java
•
•
•
•
Java Programming Language (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Java Platform
Java Programming Language
• An object oriented language
• Syntax is similar to C, C++
• Fulfills following primary goals of object oriented language:
•
•
•
•
Uses the object-oriented methodology
Allows the same program to be executed on multiple operating systems
Contains built in support for using computer networks
Executes code securely from remote sources
• It is widely used standard in enterprise programming
Java Runtime Environment (JRE)
• Also known as Java Runtime
• Part of Java Development Kit (JDK)
• JDK is a set of programming tools required for developing Java apps
• JRE consists of• Java libraries
• Java Virtual Machine
• Other components essential for running java applications
JVM
• It is an application that actually executes the java program
• When JVM is installed on a computer,
• It can run Java programs.
• Java programs therefore needn’t be self-sufficient, and
• they don’t have to include all the machine-level code that actually runs on the computer.
• Instead, Java programs are compiled into compact bytecodes, and
• the JVM reads and interprets these bytecodes to run your program.
• E.g. when you are downloading and applet from internet, you are actually downloading a
bytecode
• JVM ensures that Java programs include less code, because
• all the machine-level code to run your program is already on the target computer and
doesn’t need to be downloaded.
JVM
• JIT Compiler
• Initially java programs were interpreted- i.e. executed bytecode by bytecode
• Interpretation can be a slow process
• To solve this, Java2 comes with JIT compiler• It actually reads your bytecodes in sections and compiles them interactively into
machine language, so that the program can run faster
• (the whole program is not compiled at once because java performs runtime checks on
various sections of the code)
The Java Platform
• Over the years, the Java platform evolved into three major editions, each
addressing a distinct set of programming needs:
• The Java Platform, Standard Edition (Java SE)
• Most commonly used among the three editions
• Used for developing desktop and console-based applications
• It consists of:
• A runtime environment
• Set of APIs, to build a wide variety of applications comprising standalone applications that can run
on various platforms- Windows, Linux, Solaris
• The Java Platform, Enterprise Edition (Java EE)
• Used for building server-side applications, by using its component-based approach
• The Java Platform, Micro Edition (Java ME)
• Used for computing micro devices- handheld devices- PDAs, mobile phones – with limited
display and memory support
Section B: Enterprise Architecture
Enterprise Architecture
• Enterprise architecture
• Helps in understanding the structure of an enterprise application
• It can be broken down into three fundamental logical layers:
• User interface layer
• Displays data elements to the users and collecting data from the users
• Often called the ‘presentation’ layer- it includes the part of the software that creates and
controls the user interface and validates the user’s actions
• Processing layer
• Helps an application to work and handle processing of business logic
• Also called the ‘business layer’
• Data storage & access
• Helps the processing layer to read and store data
Enterprise Architecture Types
• An enterprise application can be designed in many ways,
• but, here we discuss the following types of enterprise architectures:
•
•
•
•
Single-tier architecture
2-tier architecture
3-tier architecture
n-tier architecture
Single-tier Architecture
• It consists of
• the presentation, the business rules, and the data access layers
• in a single computing layer.
• Such applications are
• relatively easy to manage,
• and implement data consistency, since data is stored in a single location
• Problem• Such applications can’t be scaled up to handle
• multiple users, and
• they do not provide an easy means of sharing data across enterprise
2-tier Architecture
• It separates the data and business logic.
• the application resides entirely on the local machine, and
• the database is deployed at a specific and secured location.
• In 2-tier application (a. k. a. client-server application),
• the processing load is entrusted with the client,
• while the server simply controls the traffic between the application and data
1st Layer
Presentation Logic
Data Layer
Business Logic
Data Access
Layer
Database
2-tier Architecture
3-tier Architecture
• In 3-tier architecture, an application is virtually split into three
separate logical layers
3-tier Architecture
• Layers:
• First tier: ‘presentation layer’- consists of a GUI to interact with the user
• Middle tier: ‘business layer’- consists of the application (or business) logic;
• Third tier: ‘data layer’ – contains data access logic needed for the application.
• This separation of application logic from the user interface adds
enormous flexibility, as compared to the 2-tier system, to the design
of an application.
• By using this architecture, multiple user interfaces can be built and deployed
without changing the application logic; provided it defines a clear interface to
the presentation layer.
2-tier vs. 3-tier
n-tier Architecture
• There can be numerous layers in this kind of architectures.
• In this model,
• The user interface logic is retrieved from the application running on the
desktop.
• The application on the desktop is responsible for presenting the user interface
to the end user and for communicating to the business logic tier.
• It is no longer responsible for enforcing business rules or accessing databases.
• There is no hard & fast way to define an application in this architecture.
• In fact, n-tier architecture can support a number of different configurations.
n-tier Architecture
• It can be virtually distributed in to the following segments:
n-tier Architecture
• Advantages
• Improved maintainability
• Such applications are easier to maintain
• Consistency
• By means of component designing and their association with the layer in the
architecture where they are providing functionality
• Interoperability
• Such applications are highly interoperable, as we can implement components in different
layers to support different technologies and platforms
• Flexibility
• Developer is free to design and develop various types of components for different layers
with all flexibility
• Scalability
• We can add new components without affecting the performance of the existing
application
Goals of enterprise applications
• Ensure robustness
• Ensure scalability and performance
• Implement OO design principles
• Avoid complexity
• Ensure maintainability and extensibility
• Ensure ease of testing
• Promote reuse of applications
• Support for multiple client types
• portability
Section C: Java EE Platform
Applications Development Requirement
• Platform independence - Do not get caught in complexity of operating systems
• Develop Once, run every
• Strong framework, ensure repeatability – Ensure building blocks
• Flexibility in individual implementation over common rules
• Internationalization requirements
• Access of business rules including data and methods
• Reduced dependency on database
• Organization component modelling
• Standardization with Business entities
• Technology Portability
• Ability to change business rules easily
What is J2EE?
• J2EE is a standard based platform for
developing, deploying and managing multitier, web-enabled, server centric and component based enterprise applications
• J2EE enhances J2SE with:
•
•
•
•
Enterprise JavaBeans components
Java Servlets API
Java Server Pages
XML
• This suite is the Java 2 Enterprise Edition, commonly known as J2EE.
• J2EE (Java2 Enterprise Edition) offers a suite of software specification to design, develop, assemble and deploy
enterprise applications.
• It provides a distributed, component-based, loosely coupled, reliable and secure, platform independent and responsive
application environment.
• J2EE environment provides a framework for bundling together the components into an application and provide the
applications necessary common services such as persistence, security, mail, naming and directory service etc.
• Java 2 Platform, Enterprise Edition (J2EE) defines the standard for developing component-based multi-tier distributed
enterprise applications.
• A J2EE component is a self-contained functional software unit that is assembled into a J2EE application along with
related components.
• Application logic is divided into components according to function
Exploring the Java EE5 platfom
• It comprises of the following:
• A runtime infrastructure for managing and hosting applications. All runtime
applications are hosted in this server.
• A set of Java APIs to build applications. These Java APIs describe the
programming model for Java EE appliations.
The Runtime Infrastructure
• It includes numerous services to manage enterprise applications.
• The Java EE architecture provides the uniform means of accessing
platform-level services via its runtime environment.
• These services include:
• messaging, security and distributed transactions
The Java EE APIs
• In the enterprise services, the distributed applications require server
access for running.
• These enterprise services include transaction processing, managing,
multithreading, and database access.
• J2EE5 unifies access to such services in its enterprise service APIs.
• The j2ee5 application program can access these APIs through the
containers such as Web and EJB,
Java EE APIs
EJB 3.0
• An enterprise bean is a server-side piece of code with fields and
methods to implement the modules of the business logic.
• It is a building block that can be used alone or with other enterprise
beans to execute the business logic on the Java EE server
• It is a component based architecture for developing, deploying, and
managing reliable enterprise applications
Java Servlet Technology
• It allows you to define HTTP-specific servlet-classes.
• A servlet class extends the capabilities of servers that host the
applications accessed by the way of request-response programming
model.
Java Server Pages & JSP Tag Library(JSTL)
• It allows you to integrate the combined snippets of Java code with
static markup in a text-based document.
• It is a text-based document that contains two types of text:
• Static template data, which can be expressed in any text-based format such as
HTML or XML
• JSP elements, which determine how the page constructs the dynamic content
• JSTL provides a set of standard tags that can be used in a JSP page
• It provides tags to use java code embedded in a JSP page
• It includes various tags to control the flow of execution, to support
internationalization and to access database using SQL
Java Server Faces
• Provides component based API for building rich user interfaces for
web applications.
• Used in conjunction with JSP and servlets
• They handle all the complexities of managing the UI, enabling the
developer to concentrate on the business logic.
Java Message Service (JMS)
• The JMS API is a messaging standard that allows Java EE application
components to create, send, receive, and read messages.
• It enables distributed communication that is loosely coupled, reliable,
and asynchronous.
Java Transaction API(JTA)
• JTA is used to manage distributed transactions.
• This API specifies a standard java interface for a transaction manager
to interact with the resource manager, application server, and
transactional appliacations.
JavaMail API
• Many enterprise applications need to send email notifications.
• Java EE platform includes the JavaMail API with a JavaMail Service
provider that application components can use to send emails.
• It has two parts:
• An application-level interface used by the application components to send
emails
• A service provider interface
JavaBeans Activation Framework (JAF)
• it provides the standard services –
•
•
•
•
to determine the type of an arbitrary
to encapsulate access to it
to identify the operations available on it, and
to instantiate appropriate JavaBean components to perform these operations
Java API for XML Processing (JAXP)
• it enables applications to parse, transform, validate, and query XML
documents
• This API is independent of XML processor implementation
Java API for XML Web Services(JAX-WS)
• The JAX-WS specification helps
• create web service endpoints and client components to access the web
services.
• It also describes the deployment information of web services and
clients.
• It also supports JAXB
• JAXB API is used to bind XML data to java objects.
Java Architecture for XML Binding(JAXB)
• It helps on binding an XML schema with a java object in a simple and
easy way.
• It helps in marshalling java content tree into XML instance
documents, and vice versa.
JDBC API
• The Java DataBase Connectivity API helps execute SQL commands
from Java programs.
• JDBC API can be used with
•
•
•
•
Enterprise java beans,
JSP,
Servlets, and
Java classes
Java Persistence API (JPA)
• In Java EE, a solution for persistence has been provided in the form of
JPA.
• An object relational mapping, which is used by persistence, is used for
bringing an OO model and relational database model together.
• JPA consist of
• the Persistence API,
• query language, and
• object/relational mapping metadata.
Java Naming and Directory Interface (JNDI)
• It provides the naming and directory functionality.
• It provides Java EE applications with the methods to perform standard
directory operations, such as
• associating attributes with the objects and searching for the objects by using
their attributes.
• Using JNDI, a Java EE application can store and retrieve any type of
named Java objects.
Java Authentication and Authorization Service
(JAAS)
• JAAS provides a way for a Java EE application to authenticate and
authorize a specific user or group of users.
• JAAS is a Java based standard Pluggable Authentication Module (PAM)
framework,
• which extends the Java platform security architecture to support user-based
authorization.
J2EE Suite (summary)
• Core technology: Container infrastructure, language and environment support
• XML technology
• The Java API for XML Processing (JAXP)
• The Java API for XML-based RPC (JAX-RPC)
• SOAP with Attachments API for Java (SAAJ)
• The Java API for XML Registries (JAXR)
• Web Technology
• Java Servlets
• JavaServer Pages
• JavaServer Pages Standard Tag Library
• Enterprise Java Bean (EJB) technology
• Session beans
• Entity beans
• Enterprise JavaBeans Query Language
• Message-driven beans
• Platform services
• Security
• Transactions
• Resources
• Connectors
• Java Message Service
Architecture of Java EE 5
Distributed Multi-tiered Applications
• Services, clients (people and application) and data are distributed
geographically across many platforms and many machines.
• Multiple tiers:
•
•
•
•
Client-tier (browser or client-application)
Web-tier (web-server: Java Server Pages)
Business-tier (logic; Examples: Enterprise Java Beans)
Enterprise-Information-System (EIS) tier (database)
Enterprise Application Model
J2EE Multi-tier Framework
ANY CLIENT
WEB CLIENT
Client
Tier
JSP/Servlet
Container
Web
Tier
EJB Container
Database/Legacy Systems
Client
Machine
J2EE
Server
Business
Tier
EIS Tier
Database
Server /
Legacy
Server
J2EE Architecture
CLIENTS
TIER
External Clients
from
INTERNET
(Browsers , WAP
etc.) Applets
J2EE WEB APPLICATION SERVER TIER
PRESENTATION
LOGIC
BACK END
TIER
BUSINESS LOGIC
(EJB Container )
(Web Components)
SERVLETS
JSP
EJB
EJB
EJB
EJB
Enterprise
Information
Systems
EJB
EJB
(Databases,
ERP,
Legacy
Systems)
XML
Internal Clients
from INTRANET
(Browsers , Desk
top
Applications etc.)
Applets,
Javabeans
ENTERPRISE SERVICES
WML
JDBC
JNDI
JMS
HTML
RMI - IIOP
JTS
J2EE-based Application
• The J2EE APIs enable distributed systems and applications through the following:
• Unified application model across tiers with enterprise beans
• Simplified response and request mechanism with JSP pages and servlets
• Reliable security model with JAAS
• XML-based data interchange integration with JAXP
• Simplified interoperability with the J2EE Connector Architecture
• Easy database connectivity with the JDBC API
• Enterprise application integration with message-driven beans and JMS, JTA, and JNDI
J2EE Technology Architecture
html
Web clients
Application clients
IIOP,
others
Java Server
pages
Servlets
Enterprise Java Beans Components
Server
platform
JTS
JMAPI
JNDI
JMS JAXP JDBC JAAS
…
J2EE offerings for Developer
Java Authentication &
Authorization Service
Enterprise Java
Beans
Java Naming &
Directory Interface
JAXP – JAXB –
JAXR – JAXRPC
Java Servlet
Technology
J2EE
JDBC
Java Server Pages
Java Message Service
Java Transaction API
& Service
JTA + JTS
SAAJ (Web Services)
JavaMail API
J2EE Application Components
• J2EE applications comprises various components.
• Client Components
• Built using applets which runs on client machine
• Web Compoents
• Built using Java Servlet technology and JSP technology which runs on server.
• Business Compnents
• Built using EJB technolgy which runs on server.
• Web clients
• Dynamic web pages with HTML, rendered by web browsers.
• Can include applets.
• Communicates with server typically using HTTP.
• Application clients
• User interface using GUI components such as Swing and AWT.
• Directly accesses the business logic tier.
Web Components
• J2EE Web components can be either servlets or JSP pages
• Servlets are Java programming language classes that dynamically process requests and
construct responses.
• JSP pages are text-based documents that execute as servlets but allow a more natural
approach to creating static content
• Static HTML pages and applets are bundled with Web components during application
assembly, but are not considered Web components by the J2EE specification.
• Server-side utility classes can also be bundled with Web components and, like HTML
pages, are not considered Web components.
Web Tier
Business Tier
•Business code, which is logic that solves or meets the needs of a
particular business domain such as banking, retail, or finance, is
handled by enterprise beans running in the business tier.
Java 2 Enterprise Edition (J2EE)
Example
J2EE server
HTTP Request
Web Container
Servlet
HTTP Response
Client
(Browser)
Bean1
Bean2
EJB Container
Database
Containers
• Containers are a central theme in J2EE architecture.
• Containers are like the rooms in the house• People and things exist in the rooms, and interface with the infrastructure
through well-defined interfaces.
• In an application server,
• Web and business components exist inside the containers and interface with the Java EE
infrastructure through well-defined interfaces.
J2EE Containers
• What is a Container
• Containers are the interface between a component and the
low-level platform specific functionality that supports the
component.
• How does it work
• Container settings are specified for each component during
assembly process before deployment.
• What do I get
• Support for security, transaction management, JNDI lookup,
Remote connectivity.
J2EE Containers (cont..)
– Manage life cycle of
objects
– Manage transactions
– Provide security
– Resource optimization
•DB pooling
•Compiled JSP Caching
– Persistence support
•CMP (EJB-QL)
Types of Containers
• EJB Container
• Web Container
• Application Client Container
• Applet Container
Compilation and Deployment
• Compilation (building the executables) uses build tool such as Apache
Ant.
• The components of the various tiers are packaged: .jar, .war, .ear
• Declarative resources are added.
• A deploy tool or management tool is used to deploy the packaged
units into a J2EE server (container).
Thank You