1 / 49

Self-executing Java, J2EE

Self-executing Java, J2EE. James Atlas July 29, 2008. Review. Software Testing Design process. Announcements. Final Exam 08/15 at 3:30PM to 5:30PM in 107 Sharp Lab (SHL107) We will have a review on 08/12, no class on 08/14 Remaining topics Java Security 3D graphics API + Sound. Today.

zenia
Download Presentation

Self-executing Java, J2EE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Self-executing Java, J2EE James Atlas July 29, 2008

  2. Review • Software Testing • Design process James Atlas - CISC370

  3. Announcements • Final Exam • 08/15 at 3:30PM to 5:30PM in 107 Sharp Lab (SHL107) • We will have a review on 08/12, no class on 08/14 • Remaining topics • Java Security • 3D graphics API + Sound James Atlas - CISC370

  4. Today • Self-executing Java • J2EE Intro James Atlas - CISC370

  5. Self-executing Java • "How do I make an .EXE file from my Java application?“ • Many different approaches: • Executable Jars • Java Web Start • Custom launcher/wrapper • Ahead-Of-Time Compilers James Atlas - CISC370

  6. Executable Jars • “zip” archive containing application code and resources • contains a META-INF/MANIFEST.MF file • Main-Class: MyAppMain • Class-Path: mylib.jar • automatically associated in Windows with your installed JRE (javaw.exe) • requires a working, installed JRE James Atlas - CISC370

  7. Java Web Start • From a web-link it automatically downloads application to a local cache and launches it • Less secure than Applets (with user confirmation) • Internet connectivity required • Similar to:java -classpath http://www.mysite.com/app/MyApp.jar com.mysite.app.Main • Example:http://www.calcexp.com/weblaunch.htm James Atlas - CISC370

  8. Custom launcher/wrapper • Creates a small native program that calls the appropriate java commands • Allows custom taskbar icons and splashscreens • Can be configured to use a bundled JRE • Launch4J - http://launch4j.sourceforge.net/ James Atlas - CISC370

  9. Ahead-Of-Time Compilers • Produces a conventional native executable for the target platform • Pros: • performance • Intellectual Property • No “warm-up” time • Cons: • limited tools depending on what version of Java • very hard to do dynamic applications (custom classloaders like web servers with JSP content) • produces executable that is platform specific but somewhat hardware agnostic James Atlas - CISC370

  10. Programming Assignment 5 James Atlas - CISC370

  11. J2EE James Atlas - CISC370

  12. History • Initially two tier architecture (client server applications) • Client is responsible for data access applying business logic and presentation of data • Only service provided by Server was that of database server. James Atlas - CISC370

  13. Two Tier Application Architecture Client Server James Atlas - CISC370

  14. Two Tier Application Architecture • Drawbacks • Easy to deploy but difficult to enchance or upgrade. • It makes reuse of business and presentation logic difficult • Not scalable and not suited for internet James Atlas - CISC370

  15. J2EE • To develop N tier application • It supports the development of a variety of application types • small client server systems • Systems running on Intranets • Systems on large scale internet e-commerce site James Atlas - CISC370

  16. J2EE Features • Component based model • Container provided services • Highly Scaleable • Simplified Architecture • Flexible security model James Atlas - CISC370

  17. Key J2EE APIs • Component Technologies • Servlets • Java Server Pages (JSP) • Enterprise Java Beans (EJB) • Standard Services • Java Database Connectivity (JDBC API) • Java Naming and Directory Interface (JNDI) • Java Transaction API (JTA) • Other Services • HTTP, HTTPS, RMI-IIOP, JMS, JavaMail James Atlas - CISC370

  18. Containers in the N-Tier J2EE Architecture James Atlas - CISC370

  19. 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 James Atlas - CISC370

  20. J2EE Application Model • Browser is able to process HTML and applets pages. • It forwards requests to the web server, which has JSPs and Servlets • Servlets and JSPs may access EJB server. • Java Standalone runs on java client, which access EJB server using RMI. James Atlas - CISC370

  21. J2EE Application Model James Atlas - CISC370

  22. 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) James Atlas - CISC370

  23. 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 James Atlas - CISC370

  24. EJB – Enterprise Java Beans • Entity Beans • Session Beans • Message Beans • New in EJB 2.0 James Atlas - CISC370

  25. Client / EJB Relationship • 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 James Atlas - CISC370

  26. EJB – Enterprise Java Beans • Entity Beans • Session Beans • Message Beans • New in EJB 2.0 James Atlas - CISC370

  27. EJB – Entity Beans • 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. James Atlas - CISC370

  28. Entity Beans - Persistence • Container Managed Persistence (CMP) • 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 • Bean Managed Persistence (BMP) • 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 James Atlas - CISC370

  29. EJB – Session Beans • Session beans perform work for a client application • For example, a session bean could charge a credit card for a specific transaction. James Atlas - CISC370

  30. Session Beans – State • 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 James Atlas - CISC370

  31. EJB – Session Bean Example package org.jboss.docs.interest; import javax.ejb.EJBObject; import java.rmi.RemoteException; /** 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. */ public interface Interest extends EJBObject { /** Calculates the compound interest on the sum `principle', with interest rate 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 can demonstrate that the method is actually being executed on the server, rather than the client. */ public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException; } James Atlas - CISC370

  32. EJB – 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; } James Atlas - CISC370

  33. EJB – 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) {} } James Atlas - CISC370

  34. EJB – 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> James Atlas - CISC370

  35. 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. */ 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()); } } } James Atlas - CISC370

  36. EJB – Message Beans • 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. James Atlas - CISC370

  37. JMS Queue JMS – Java Message Service James Atlas - CISC370

  38. JMS Topic JMS – Java Message Service James Atlas - CISC370

  39. 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 James Atlas - CISC370

  40. Example EJB Application James Atlas - CISC370

  41. Servlets • Are 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 James Atlas - CISC370

  42. JavaServer Pages (JSP) • 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. • Installed on web server • Web components that sit on top of java servlets James Atlas - CISC370

  43. J2EE Application Packaging James Atlas - CISC370

  44. JBoss James Atlas - CISC370

  45. What is JBoss • Created in 1999, JBoss is the product of an OpenSource developer community dedicated to developing the best J2EE-compliant application server in the market • With 1000 developers worldwide and a steadily growing number of downloads per month, reaching 72,000 for October ’01 (per independent www.sourceforge.net), JBoss is arguably the most downloaded application server in the world today • Distributed under an LGPL license, JBoss is absolutely FREE for use. No cost. Period. James Atlas - CISC370

  46. What is Application Server • 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 James Atlas - CISC370

  47. JBoss- Application Server James Atlas - CISC370

  48. JBoss - example James Atlas - CISC370

  49. Project 2 • Need to setup group meeting time James Atlas - CISC370

More Related