J2EETM : Why, What and How - PowerPoint PPT Presentation

1 / 92
About This Presentation
Title:

J2EETM : Why, What and How

Description:

Then, Java needs to run on the server too to be more useful enterprise ... Umbrella for anything Java-related ... Server is Java program that runs as separate ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 93
Provided by: utda
Learn more at: http://www.utdallas.edu
Category:
Tags: j2eetm | java

less

Transcript and Presenter's Notes

Title: J2EETM : Why, What and How


1
J2EETM Why, What and How
  • University of Texas at Dallas
  • Anna Yi

2
Objectives
  • Why J2EE?
  • What is J2EE?
  • How to use J2EE?

3
Motivation for J2EE
Why J2EE?
  • Need for
  • New multi-tier enterprise computing model in web
    environment
  • A way to bring in different elements of
    enterprise application
  • Web interface design
  • Transaction processing
  • Meeting non-functional system requirements
  • Availability, reliability, enhanceability,
    performance, scalability, reusability,
    interoperability
  • Timely development and deployment

4
Two-tier Client/Server Architecture
Why J2EE?
Server
Client
5
Simple Web Client/Server
Why J2EE?
  • Interaction of two-tier architecture
  • Client simply accesses web pages through web
    browser
  • Server retrieves html documents

6
CGI-based Web Client/Server
Why J2EE?
  • Interaction of two-tier architecture
  • Client uses service requiring 2ndary storage
  • Server manipulates forms, Database updates,
    (primitive) electronic commerce
  • Fat Server/ Thin Client

7
Java Applet-based Web Client/Server
Why J2EE?
  • Interaction of two-tier architecture
  • Client uses Java Applet for client-side
    computation
  • Server provides Applet bytecode
  • Fat Client/Thin Server

8
Two-tier Client/Server Architecture
Why J2EE?
  • So, important processing needs to be run on the
    server
  • Then, Java needs to run on the server too to be
    more useful ? enterprise
  • The server is almost like what CGI-programming
    does
  • Client data access applying business logic and
    presentation of data (computation)
  • Server serves only as service-database server,
    not application server web server
  • But what is the problem with this architecture?

9
Drawbacks of two tier application architecture
Why J2EE?
  • Easy to deploy, but difficult to enhance or
    upgrade
  • Reusability of business and presentation logic
    difficult
  • Not scalable

10
Vision of J2EE
Why J2EE?
  • An open standard
  • Umbrella for anything Java-related
  • For designing, developing, assembling, and
    deploying component-based enterprise applications
  • Separation of business logic from presentation
  • Reusability, enhanceability, scalability,
    interoperability

11
Separation of Business logic from Presentation
logic
Why J2EE?
  • Presentation logic display
  • Business logic what the company wants to do
  • Example the distribution of different sales
    figures by diff dept (business logic) can be
    represented in many different ways (pie chart,
    bar graph, etc)

12
Why J2EE?
  • Simplifies the complexity of a building n-tier
    application
  • Standardizes an API between components and
    application server container
  • J2EE Application Server and Containers provide
    the framework services

13
What is J2EE?
  • Defines the standard for developing multitier
    enterprise applications
  • Simplifies enterprise applications by
  • Basing them on standardized, modular components
  • Providing a complete set of services to those
    components
  • Handling many details of application behavior
    automatically, without complex programming

14
Thin-client Multi-tiered Architecture
What is J2EE?

15
J2EE Tiers
  • Client Presentation
  • HTML or Java applets deployed in Browser
  • XML documentations transmitted through HTTP
  • Java clients running in Client Java Virtual
    Machine (JVM)
  • Presentation Logic
  • Servlets or JavaServer Pages running in web
    server
  • Application Logic
  • Enterprise JavaBeans running in Server

16
J2EE Components Services
  • Components
  • Java Servlets
  • JavaServer Pages (JSP)
  • Enterprise JavaBeans (EJB)
  • Standard services supporting technologies
  • Java database connectivity(JDBC) data access API
  • Java Messaging Service (JMS)
  • (Remote Method Invocations (RMI))
  • Extensible Markup Languages(XML)
  • JavaIDL (Interface Description Language)
  • JavaMail
  • Java Security
  • CORBA technology
  • Design Patterns

17
Advantages of Multi-tiers
  • Tiers separate functionality
  • Presentation Logic, Business Logic, Data Schema
  • Easier upgrade since one tier can be changed
    without changing the rest
  • Lower deployment and maintenance cost
  • More flexible (can support changes), more
    extensible (can add functionality)

18
(No Transcript)
19
The Big Picture
What is J2EE?
20
4-Tier Model
What is J2EE?
Web Tier
Client Tier
EIS Tier
Business Tier
21
Commercial Platforms
What is J2EE?
  • J2EE SDK 1.3 (Sun)
  • WebLogic (BEA Systems)
  • WebSphere (IBM)
  • iPlanet (Sun NetScape)
  • JBoss (Open source)

22
What is Application Server
What is J2EE?
  • Application servers enable the development of
    multi-tiered distributed applications. They are
    also called middleware
  • An application server acts as the interface
    between the database(s), the web servers and the
    client browsers

23
Application Server Key Services
24
JBoss- Application Server
25
J2EE Components
What is J2EE?
  • Java Servlets
  • JavaServer Pages (JSP)
  • Enterprise JavaBeans (EJB)

26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
Overview of Servlets
What is J2EE?
  • Container-managed web components
  • Replace Common Gateway Interface(CGI) or Active
    Server Pages (ASP)
  • Generate dynamic response to requests from web
    based clients
  • Synchronize multiple concurrent client request
  • Serve as client proxies

32
Servlet Operation
What is J2EE?
  • Server is Java program that runs as separate
    thread inside servlet container.
  • Servlet container is part of web server
  • It interact with web client using response
    request paradigm

33
JavaServer Pages (JSP)
What is J2EE?
  • Text based documents describe how to process a
    request and create a response
  • Contains HTML or XML and other JSP elements
    defined by JSP specification.
  • Are Installed on web server
  • are web components that sits on top of java
    servlet mode.

34
JSP Advantages
What is J2EE?
  • Performance
  • Runtime characteristics of servlets
  • uses Lightweight threads
  • Doesnt start new process for each request,
    Initialized
  • once and persists in memory for multiple
    requests, cached
  • Automatic recompilation of modified pages
  • Server side processing
  • Programming
  • Emphasize use of reusable components
  • Write Once , Run Anywhere properties
  • Extensible through custom tag libraries
  • Provides front end access mechanism to EJBs

35
Parts of JSP Pages
What is J2EE?
  • Directive
  • MVCApp.CartItem
  • Declaration
  • Vector cpi null
  • Raw HTML
  • Shopping Carttml
  • Action
  • MVCApp.Cart/
  • Scriplets
  • Cpi cart.getCartItems ( )
  • it cpi.iterator()
  • While (it.hasNext())ci (Cart Item)it.next()

36
Parts of JSP Pages
What is J2EE?
  • Expression
  • Implicit Objects

37
Enterprise Java Beans (EJBs)
What is J2EE?
  • Entity Beans
  • Represent persistent business Entity
  • Persisted in storage system ( usually Database)
  • Might contain Application logic intrinsic to
    entity
  • Session Beans
  • Perform work for individual clients on the server
  • Encapsulate complex business logic
  • Can coordinate transactional work on multiple
    entity beans

38
States and Persistence
What is J2EE?
  • Session beans can be
  • Stateless- belong to client for duration of a
    method call
  • Stateful- belong to client for duration of client
    conversation
  • Entity beans can have
  • Bean-managed persistence- The developer writes
    SQL code to retrieve,store and update database
  • Container managed persistence- The developer
    provide database mapping information that allows
    the container to manage persistence

39
Example of EJB Application
What is J2EE?
  • It consists of number of clients accessing
    session beans and entity beans
  • Each Session bean provides specialized processing
    on behalf of client
  • e.g. Travel Agent session bean makes travel
    reservations while Flight Scheduler bean
    schedules planes to fly on various routes.
  • Each Entity Bean represent different type of
    business entity.
  • e.g.Passengers, seats, planes, flights are
    entity beans

40
Example Travel Agency
What is J2EE?
41
How to use J2EE ?
How to use J2EE?
  • Using J2EE SDK 1.3.1 to Design, Develop, Assemble
    and Deploy Applications

42
How to run J2EE application on J2EE SDK 1.3.1
  • Preparation
  • Write and compile codes
  • to Assemble, Deploy, and Run the
    application
  • Packaging
  • Creating the J2EE Application (.ear)
  • Creating the Enterprise Bean (.jar)
  • Creating the Web Client (.war)
  • Deploying
  • Running

43
Preparation
  • Install J2EE SDK 1.3.1 on your system
  • Set Environment Variables
  • JAVA_HOME
  • root directory of J2SE SDK installation
  • J2EE_HOME
  • root directory of J2EE SDK installation
  • PATH
  • PATHJAVA_HOME\binJ2EE_HOME\bin
  • CLASSPATH
  • CLASSPATHJ2EE_HOME\lib\j2ee.jar

44
Creating Web Component
  • When web client such as browser communicates with
    J2EE application, it dose so through server-side
    objects called Web components
  • Writes and compiles the source code
  • Bundles the .class, .jsp, .html files into WAR
    file

45
Creating Enterprise Bean
  • An enterprise bean is a server-side component
    that contains the business logic of an
    application
  • Write and compile the source code
  • Package the beans classes into EJB JAR file
  • Remote Interface
  • Home Interface
  • Enterprise Bean Class

46
(No Transcript)
47
(No Transcript)
48
Remote Interface
  • WebAddressAccount.java
  • defines the business methods that a client may
    call. The business methods are implemented in the
    enterprise bean code
  • public interface WebAddressAccount extends
    EJBObject
  • public String getUrlName()
  • public String getUrlDescript()

49
Home Interface
  • WebAddressAccountHome.java
  • defines the methods that allow a client to
    create, find, or remove an enterprise bean
  • public interface WebAddressAccountHome extends
    EJBHome
  • public WebAddressAccount create(String
    urlName, String urlDescript)
  • public WebAddressAccount findByPrimaryKey(Str
    ing urlName)

50
Enterprise Bean Class
  • WebAddressAccountBean.java
  • implements the business methods
  • public class WebAddressAccountBean implements
    EntityBean
  • public String getUrlName() return
    urlName
  • public String getUrlDescript() return
    urlDescript
  • public String ejbCreate( String urlName, String
    urlDescript)
  • insertRow( urlName, urlDescript)
  • public String ejbFindByPrimaryKey(String
    primaryKey)
  • result selectByPrimaryKey(primaryKey)

51
Start J2EE SDK to Assemble, Deploy, and Run the
application
  • Start Cloudscape database server.
  • C\ cloudscape start
  • Start J2EE server
  • C\ j2ee verbose
  • Start deploytool
  • C\ deploytool
  • Build the database table
  • C\ cloudscape isql

52
(No Transcript)
53
Packaging
  • Create an Enterprise Archive (EAR) file
  • ProjectApp.ear
  • Add Java Archive (JAR) files and Web Archive
    (WAR) files to the EAR
  • WebAddressAccountJAR contains the enterprise
    bean files and related files
  • ProjectWAR contains the Web Component files and
    related files

54
Example BonusApp
  • Objective
  • To calculate bonus for an employee
  • 3-Tier Example using Session Bean
  • 4-Tier Example using Entity Bean

55
3 Tier Example using session bean
  • Create HTML page
  • Create Servlet
  • Create the Session Bean
  • Compile the Session Bean and Servlet
  • Start the J2EE Application Server
  • Start the Deploy tool
  • Assemble the J2EE application
  • Specify JNDI Name and Root Context
  • Verify and Deploy the J2EE application
  • Run the J2EE application

56
3 Tier Example using session bean
  • 3-tier
  • Html page
  • Servlet
  • Session Bean

57
bonus.html
B
onus Calculation bonusServlet" Enter social security
Number UT Enter Multiplier NAME"MULTIPLIER" TYPE"SUBMIT" VALUE"Submit" TYPE"RESET"
58
(No Transcript)
59
BonusServlet.javapublic class bonusServlet
extends HttpServlet
60
Create Session Bean CalcHome, Calc, CalcBean
61
CalcHome.Java
BonusServlet does not work directly with the
session bean, but creates an instance of its home
interface. The home interface extends EJBHome and
has a create method for creating the session bean
in its container.
62
Calc.java
When the home interface is created, the J2EE
application server creates the remote interface
and session bean. The remote interface extends
EJBObject and declares the calcBonus method for
calculating the bonus value. This method is
required to throw javax.rmi.RemoteException, and
is implemented by the CalcBean class.
63
CalcBean.java
The session bean class implements the SessionBean
interface and provides behavior for the calcBonus
method. The setSessionContext and ejbCreate
methods are called in that order by the container
after BonusServlet calls the create method in
CalcHome.
64
Source Codes
Calc.java
CalcBean.java
65
Start the Application Server
  • Start the Application Server
  • J2ee verbose
  • Start the deploytool
  • deploytool

66
Assemble the J2EE Application
  • 1. Create a new J2EE application (BonusApp.ear).
  • 2. Create a new enterprise bean (CalcBean.jar).
  • 3. Create a new web component (Bonus.war).
  • 4. Specify JNDI name for the enterprise bean
    (calcs).
  • 5. Specify the Root Context for the J2EE
    application (BonusRoot).

67
2. Create a New EnterpriseBean
68
3. Create a new web component (Bonus.war).
69
JNDI Names and Resource References
  • JNDI Java Naming and Directory Interface
  • J2EE components locate objects by invoking the
    JNDI lookup method
  • The JNDI name of a resource and the name of the
    resource reference are not the same
  • This approach to naming requires that you map the
    two names before deployment

70
Specifying a Resource Reference
The WebAddressAccountBean code refers to the
database as follows private String dbName
"javacomp/env/jdbc/WebAddressAccountDB"
71
Mapping Resource Referenceto JNDI Name
72
Deploy the application
73
Run the application
  • In the browser, type http//localhost8000/BonusRo
    ot/bonus.html
  • Fill in a social security number
  • Fill in a multiplier
  • Click the Submit button. BonusServlet processes
    your data and returns an HTML page with the bonus
    calculation on it.

74
4 Tier Example using entity bean/cooperating
enterprise beans
  • 4-tier
  • Html
  • Servlet
  • EJBs
  • Database

75
Create Entity Bean Bonus Home (Home interface),
Bonus (Remote interface)
76
Create Entity Bean Bonus Home (Home interface),
Bonus (Remote interface)
77
4 Tier Example using JavaServer Pages
  • 4-tier
  • Client
  • JSP
  • EJBs
  • Database

JavaServer Pages (JSP) technology lets you put
segments of servlet code directly into a static
HTML page. When the JSP Page is loaded by a
browser, the servlet code executes and the
application server creates, compiles, loads, and
runs a background servlet to execute the servlet
code segments and return an HTML page or print an
XML report.
78
(No Transcript)
79
4 Tier Example Bonus.jsp
80
Modifying the J2EE Application
  • Change the source code
  • Recompile it
  • Redeploy the application
  • Select Tools - Update Files
  • Select Tools - Deploy
  • Or
  • Select Tools - Update And Redeploy

81
Advantages Disadvantages
  • Advantages
  • Disadvantages
  • Learning curve
  • Overhead of a layered architecture no direct
    communication between layers that are apart,
    affecting performance
  • Moving target, i.e. upgraded versions

82
Conclusion Summary
  • Need for server-side/enterprise processing with
    enhanceability, reusability, and scalability
  • J2EE as a web-based, component-based multi-tiered
    client/server architecture
  • Designing, developing, assembling, and deploying
    java applications using a platform

83
Conclusion Research Issues
  • (Evolving)Vision still to be realized
  • Non-functional characteristics (enhanceability,
    reusability, scalability, security, etc)
  • Integration with other technologies such as
    CGI-programming and CORBA
  • Fuller support for design patterns in software
    lifecycle

84
Reference
  • http//java.sun.com/j2ee
  • http//www.utdallas.edu/chung/SA/2client.pdf
  • http//sdmc.krdl.org.sg8080/judice/J2EE.pdf
  • http//www.sun.com/developers/evangcentral/present
    ations/j2eeoverview.pdf
  • http//www.sun.com/developers/evangcentral/present
    ations/J2EE.pdf

85
Design Patterns Factory Method
  • The Factory Method lets a class defer
    instantiation to subclasses
  • The Factory Pattern promotes loose coupling by
    eliminating the need to bind application-specific
    classes into the code.

86
Design Patterns Factory Method
87
Design Patterns Factory Method
  • The equivalent code
  • The EJB Client code to talk to an EJB
  • import javax.naming.
  • public class EJBClient
  • public static void main (String argv)
  • // get the JNDI naming context
  • Context initialCtx new InitialContext ()
  • // use the context to lookup the EJB Home
    interface
  • AccountHome home(AccountHome)initialCtx.lookup(
    "Account")
  • // use the Home Interface to create a Session
    bean object
  • Account account home.create (10001, "Athul",
    100000000.25d)
  • // invoke business methods
  • account.credit (200000000.25d)
  • // remove the object
  • account.remove ()

88
Design Patterns Facade
The JMS class hierarchy can be somewhat daunting
at first glance. The relationships between the
classes are straight forward, but they require a
sequence of code that is often repeated within a
JMS application.
89
Design Patterns facade
  • The JMS Connection and Session Types Depending
    upon the message-delivery paradigm you choose,
    your code must work with the correct
    ConnectionFactory, Connection, and Session
    classes. Each interface has a subclass for both
    the publish/subscribe (Topic) and point-to-point
    (Queue) message models.

90
Design Patterns Facade
  • Topic and Queue Subclasses
  • Topic and Queue extend the Destination abstract
    interface. Subsequently, MessageProducer and
    MessageConsumer have subclasses for both message
    models.

91
Design Patterns Facade
  • The com.JMSFacade PackageThis is an example of
    importing and creating the JMS Facade class,
    JMSManager
  • import com.JMSFacade
  • import javax.jms.
  • public class myClass
  • JMSManager jmsMgr new JMSManager()
  • ...

92
Core J2EE Pattern Catalog
http//java.sun.com/blueprints/patterns/index.html
Write a Comment
User Comments (0)
About PowerShow.com