Self-executing Java, J2EE James Atlas July 29, 2008.
-
Upload
christina-benson -
Category
Documents
-
view
213 -
download
0
Transcript of Self-executing Java, J2EE James Atlas July 29, 2008.
Self-executing Java, J2EESelf-executing Java, J2EE
James AtlasJames Atlas
July 29, 2008July 29, 2008
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 22
ReviewReview
• Software TestingSoftware Testing Design processDesign process
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 33
AnnouncementsAnnouncements
• Final ExamFinal Exam 08/15 at 3:30PM to 5:30PM in 107 Sharp Lab 08/15 at 3:30PM to 5:30PM in 107 Sharp Lab
(SHL107)(SHL107) We will have a review on 08/12, no class on We will have a review on 08/12, no class on
08/1408/14
• Remaining topicsRemaining topics Java SecurityJava Security 3D graphics API + Sound3D graphics API + Sound
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 44
TodayToday
• Self-executing JavaSelf-executing Java
• J2EE IntroJ2EE Intro
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 55
Self-executing JavaSelf-executing Java
• "How do I make an .EXE file from my Java "How do I make an .EXE file from my Java application?“application?“
• Many different approaches:Many different approaches: Executable JarsExecutable Jars Java Web StartJava Web Start Custom launcher/wrapperCustom launcher/wrapper Ahead-Of-Time CompilersAhead-Of-Time Compilers
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 66
Executable JarsExecutable Jars
• ““zip” archive containing application code zip” archive containing application code and resourcesand resources
• contains a META-INF/MANIFEST.MF filecontains a META-INF/MANIFEST.MF file Main-Class: MyAppMainMain-Class: MyAppMain Class-Path: mylib.jarClass-Path: mylib.jar
• automatically associated in Windows with automatically associated in Windows with your installed JRE (javaw.exe)your installed JRE (javaw.exe)
• requires a working, installed JRErequires a working, installed JRE
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 77
Java Web StartJava Web Start
• From a web-link it automatically downloads From a web-link it automatically downloads application to a local cache and launches itapplication to a local cache and launches it
• Less secure than Applets (with user Less secure than Applets (with user confirmation)confirmation)
• Internet connectivity requiredInternet connectivity required• Similar to:Similar to:
java -classpath http://www.mysite.com/app/MyApp.jar java -classpath http://www.mysite.com/app/MyApp.jar com.mysite.app.Maincom.mysite.app.Main
• Example:Example:http://www.calcexp.com/weblaunch.htmhttp://www.calcexp.com/weblaunch.htm
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 88
Custom launcher/wrapperCustom launcher/wrapper
• Creates a small native program that calls the Creates a small native program that calls the appropriate java commandsappropriate java commands Allows custom taskbar icons and splashscreensAllows custom taskbar icons and splashscreens Can be configured to use a bundled JRECan be configured to use a bundled JRE
• Launch4J - http://launch4j.sourceforge.net/Launch4J - http://launch4j.sourceforge.net/
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 99
Ahead-Of-Time CompilersAhead-Of-Time Compilers• Produces a conventional native executable for the Produces a conventional native executable for the
target platformtarget platform
• Pros:Pros: performanceperformance Intellectual PropertyIntellectual Property No “warm-up” timeNo “warm-up” time
• Cons:Cons: limited tools depending on what version of Javalimited tools depending on what version of Java very hard to do dynamic applications (custom very hard to do dynamic applications (custom
classloaders like web servers with JSP content)classloaders like web servers with JSP content) produces executable that is platform specific but produces executable that is platform specific but
somewhat hardware agnosticsomewhat hardware agnostic
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1010
Programming Assignment 5Programming Assignment 5
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1111
J2EEJ2EE
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1212
HistoryHistory
• Initially two tier architecture (client server Initially two tier architecture (client server applications) applications)
• Client is responsible for data access applying Client is responsible for data access applying business logic and presentation of databusiness logic and presentation of data
• Only service provided by Server was that of Only service provided by Server was that of database server.database server.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1313
Two Tier Application ArchitectureTwo Tier Application Architecture
Client Client ServerServer
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1414
Two Tier Application ArchitectureTwo Tier Application Architecture
• DrawbacksDrawbacks
- Easy to deploy but difficult to enchance or Easy to deploy but difficult to enchance or upgrade.upgrade.
- It makes reuse of business and presentation It makes reuse of business and presentation logic difficultlogic difficult
- Not scalable and not suited for internetNot scalable and not suited for internet
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1515
J2EEJ2EE
• To develop N tier applicationTo develop N tier application
• It supports the development of a It supports the development of a variety of application types variety of application types small client server systemssmall client server systems Systems running on IntranetsSystems running on Intranets Systems on large scale internet e-Systems on large scale internet e-
commerce sitecommerce site
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1616
J2EE FeaturesJ2EE Features
• Component based modelComponent based model
• Container provided servicesContainer provided services
• Highly ScaleableHighly Scaleable
• Simplified ArchitectureSimplified Architecture
• Flexible security modelFlexible security model
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1717
Key J2EE APIsKey J2EE APIs• Component TechnologiesComponent Technologies
ServletsServlets Java Server Pages (JSP)Java Server Pages (JSP) Enterprise Java Beans (EJB)Enterprise Java Beans (EJB)
• Standard ServicesStandard Services Java Database Connectivity (JDBC API)Java Database Connectivity (JDBC API) Java Naming and Directory Interface (JNDI)Java Naming and Directory Interface (JNDI) Java Transaction API (JTA)Java Transaction API (JTA)
• Other ServicesOther Services HTTP, HTTPS, RMI-IIOP, JMS, JavaMailHTTP, HTTPS, RMI-IIOP, JMS, JavaMail
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1818
Containers in the N-Tier Containers in the N-Tier J2EE ArchitectureJ2EE Architecture
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 1919
J2EE TiersJ2EE Tiers
• Client PresentationClient Presentation HTML or Java applets deployed in BrowserHTML or Java applets deployed in Browser XML documentations transmitted through HTTPXML documentations transmitted through HTTP Java clients running in Client Java Virtual Machine Java clients running in Client Java Virtual Machine
(JVM)(JVM)
• Presentation LogicPresentation Logic Servlets or JavaServer Pages running in web Servlets or JavaServer Pages running in web
serverserver
• Application LogicApplication Logic Enterprise JavaBeans running in ServerEnterprise JavaBeans running in Server
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2020
J2EE Application ModelJ2EE Application Model
• Browser is able to process HTML and Browser is able to process HTML and applets pages.applets pages.
• It forwards requests to the web server, which It forwards requests to the web server, which has JSPs and Servletshas JSPs and Servlets
• Servlets and JSPs may access EJB server.Servlets and JSPs may access EJB server.• Java Standalone runs on java client, which Java Standalone runs on java client, which
access EJB server using RMI.access EJB server using RMI.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2121
J2EE Application ModelJ2EE Application Model
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2222
EJB – Enterprise Java BeansEJB – Enterprise Java Beans• Enterprise Java Beans are components that are Enterprise Java Beans are components that are
deployed into containersdeployed into containers
• The container provides servicesThe container provides services Loading / InitializationLoading / Initialization TransactionsTransactions PersistencePersistence Communication with EJB clientsCommunication with EJB clients Enterprise Naming Context (JNDI name space)Enterprise Naming Context (JNDI name space)
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2323
Anatomy of an EJBAnatomy of an EJB• Remote InterfaceRemote Interface
Methods that can be accessed by the outside world.Methods that can be accessed by the outside world. Extends javax.ejb.EJBObjectExtends javax.ejb.EJBObject
• Remote Home InterfaceRemote Home Interface Life-cycle methods (create, findByPrimaryKey)Life-cycle methods (create, findByPrimaryKey) Extends javax.ejb.EJBHome which extends Extends javax.ejb.EJBHome which extends
java.rmi.Remotejava.rmi.Remote
• Bean classBean class The class performing the actual business processThe class performing the actual business process Implements an interface based on type of beanImplements an interface based on type of bean
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2424
EJB – Enterprise Java BeansEJB – Enterprise Java Beans
• Entity Beans Entity Beans
• Session Beans Session Beans
• Message BeansMessage Beans New in EJB 2.0New in EJB 2.0
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2525
Client / EJB RelationshipClient / EJB Relationship• How does a client application (Java class) utilize EJBs?How does a client application (Java class) utilize EJBs?
Lookup - JNDI ENCLookup - JNDI ENC Network protocol - RMINetwork protocol - RMI EJB container creates object with RemoteHome and Home EJB container creates object with RemoteHome and Home
interfaces – this object passes calls to the bean classinterfaces – this object passes calls to the bean class
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2626
EJB – Enterprise Java BeansEJB – Enterprise Java Beans
• Entity Beans Entity Beans
• Session Beans Session Beans
• Message BeansMessage Beans New in EJB 2.0New in EJB 2.0
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2727
EJB – Entity BeansEJB – Entity Beans• Entity beans are classes that map to individual Entity beans are classes that map to individual
entities – typically, an Entity bean references a row entities – typically, an Entity bean references a row in a database table, providing an object in a database table, providing an object representation of that database object.representation of that database object. For example, an entity bean could represent a customer, For example, an entity bean could represent a customer,
and changing the values in that entity bean would cause and changing the values in that entity bean would cause updates to that database rowupdates to that database row
• Entity beans provide an abstraction layer so that Entity beans provide an abstraction layer so that working with the entity is not specific to the storage working with the entity is not specific to the storage mechanism for that entity.mechanism for that entity.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2828
Entity Beans - PersistenceEntity Beans - Persistence• Container Managed Persistence (CMP)Container Managed Persistence (CMP)
The EJB container automatically persists the EJB The EJB container automatically persists the EJB objects, usually to a relational database where each type objects, usually to a relational database where each type of object is represented as a table, and each instance of of object is represented as a table, and each instance of the object is a row in that tablethe object is a row in that table
• Bean Managed Persistence (BMP)Bean Managed Persistence (BMP) The EJB container calls bean methods when it is The EJB container calls bean methods when it is
appropriate for the bean to load, save or update data, appropriate for the bean to load, save or update data, enforcing transactions without transaction code written by enforcing transactions without transaction code written by the bean developerthe bean developer
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 2929
EJB – Session BeansEJB – Session Beans
• Session beans perform work for a client Session beans perform work for a client applicationapplication For example, a session bean could charge a For example, a session bean could charge a
credit card for a specific transaction.credit card for a specific transaction.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3030
Session Beans – StateSession Beans – State• Stateful – A stateful bean maintains a Stateful – A stateful bean maintains a
conversational state with a client. The client conversational state with a client. The client perceives that it is only talking to one bean, and perceives that it is only talking to one bean, and that bean maintains information between callsthat bean maintains information between calls
• Stateless – A stateless bean maintains no client Stateless – A stateless bean maintains no client information between method calls – the container information between method calls – the container can substitute beans as necessary between can substitute beans as necessary between method callsmethod calls
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3131
EJB – Session Bean ExampleEJB – Session Bean Example
package org.jboss.docs.interest;package org.jboss.docs.interest;
import javax.ejb.EJBObject;import javax.ejb.EJBObject;
import java.rmi.RemoteException;import java.rmi.RemoteException;
/** This interface defines the `Remote' interface for the `Interest' EJB. Its single /** 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 method is the only method exposed to the outside world. The class InterestBean implements the method. */ implements the method. */
public interface Interest extends EJBObject public interface Interest extends EJBObject
{ {
/** Calculates the compound interest on the sum `principle', with interest rate /** Calculates the compound interest on the sum `principle', with interest rate per period `rate' over `periods' time periods. This method also prints a message per period `rate' over `periods' time periods. This method also prints a message to standard output; this is picked up by the EJB server and logged. In this way we to standard output; this is picked up by the EJB server and logged. In this way we can demonstrate that the method is actually being executed on the server, can demonstrate that the method is actually being executed on the server, rather than the client. */ rather than the client. */
public double calculateCompoundInterest(double principle, double rate, double public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException; periods) throws RemoteException;
} }
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3232
EJB – Session Bean ExampleEJB – Session Bean Example
package org.jboss.docs.interest; import java.io.Serializable; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome;
/** 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. */
Interest create() throws RemoteException, CreateException; }
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3333
EJB – Session Bean ExampleEJB – Session Bean Example
package org.jboss.docs.interest; import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext;
/** 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. */
public class InterestBean implements SessionBean { public double calculateCompoundInterest(double principle, double rate, double periods)
{ System.out.println("Someone called `calculateCompoundInterest!'"); return principle * Math.pow(1+rate, periods) - principle; }
public void ejbCreate() {} public void ejbPostCreate() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sc) {} }
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3434
EJB – Session Bean ExampleEJB – Session Bean Example
<?xml version="1.0" encoding="UTF-8"?>
<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>
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3535
EJB – Session Bean ExampleEJB – Session Bean Examplepackage 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. */
public static void main(String[] args) { try { InitialContext jndiContext = new InitialContext(); ref = jndiContext.lookup("interest/Interest"); InterestHome home = (InterestHome) PortableRemoteObject.narrow(ref, InterestHome.class);
Interest interest = home.create(); //Create an Interest object from the Home interface
System.out.println(interest.calculateCompoundInterest(1000, 0.10, 2)); } catch(Exception e) { System.out.println(e.toString()); } }
}
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3636
EJB – Message BeansEJB – Message Beans
• Message beans are classes that receive Message beans are classes that receive asynchronous notification from a Java asynchronous notification from a Java Message Service serverMessage Service server For example, a message bean could be For example, a message bean could be
activated when vendor sends a purchase order activated when vendor sends a purchase order to a JMS queue.to a JMS queue.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3737
JMS – Java Message ServiceJMS – Java Message Service
JMS Queue
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3838
JMS – Java Message ServiceJMS – Java Message Service
JMS Topic
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 3939
JMS – Java Message ServiceJMS – Java Message Service• Why should I use JMS?Why should I use JMS?
Loosely-coupled systemsLoosely-coupled systems• ConnectionlessConnectionless• Removes dependence on client and server platform / Removes dependence on client and server platform /
programming language / version programming language / version Publish / Subscribe metaphorPublish / Subscribe metaphor
• Send / receive information with many, unknown clientsSend / receive information with many, unknown clients Integration with other messaging systemsIntegration with other messaging systems
• IBM MQ-SeriesIBM MQ-Series• Microsoft Message QueueMicrosoft Message Queue
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4040
Example EJB ApplicationExample EJB Application
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4141
ServletsServlets• Are container managed web componentsAre container managed web components
• Replace Common Gateway Interface(CGI) or Replace Common Gateway Interface(CGI) or Active Server Pages (ASP)Active Server Pages (ASP)
• Generate dynamic response to requests from web Generate dynamic response to requests from web based clientsbased clients
• Synchronize multiple concurrent client requestSynchronize multiple concurrent client request
• Serve as client proxiesServe as client proxies
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4242
JavaServer Pages (JSP)JavaServer Pages (JSP)
• Text based documents describe how to Text based documents describe how to process a request and create a responseprocess a request and create a response
• Contains HTML or XML and other JSP Contains HTML or XML and other JSP elements defined by JSP specification. elements defined by JSP specification.
• Installed on web server Installed on web server • Web components that sit on top of java Web components that sit on top of java
servletsservlets
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4343
J2EE Application PackagingJ2EE Application Packaging
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4444
JBossJBoss
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4545
What is JBossWhat is JBossCreated in 1999, JBoss is the product of an Created in 1999, JBoss is the product of an
OpenSource developer community dedicated to OpenSource developer community dedicated to developing the best J2EE-compliant application developing the best J2EE-compliant application server in the marketserver in the market
With 1000 developers worldwide and a steadily With 1000 developers worldwide and a steadily growing number of downloads per month, reaching growing number of downloads per month, reaching 72,000 for October ’01 (per independent 72,000 for October ’01 (per independent www.sourceforge.net), JBoss is arguably the most www.sourceforge.net), JBoss is arguably the most downloaded application server in the world todaydownloaded application server in the world today
Distributed under an LGPL license, JBoss is Distributed under an LGPL license, JBoss is absolutely FREE for use. No cost. Period.absolutely FREE for use. No cost. Period.
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4646
What is Application ServerWhat is Application Server Application servers enable the development of Application servers enable the development of
multi-tiered distributed applications. They are multi-tiered distributed applications. They are also called “middleware”also called “middleware”
An application server acts as the interface An application server acts as the interface between the database(s), the web servers and between the database(s), the web servers and the client browsersthe client browsers
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4747
JBoss- Application ServerJBoss- Application Server
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4848
JBoss - exampleJBoss - example
July 29, 2008July 29, 2008 James Atlas - CISC370James Atlas - CISC370 4949
Project 2Project 2
• Need to setup group meeting timeNeed to setup group meeting time