Upload
hanhu
View
223
Download
0
Embed Size (px)
Citation preview
1
Extreme JavaG22.3033-006
Session 2 – Main ThemeJava Tools and Software Engineering Techniques
Dr. Jean-Claude Franchitti
New York UniversityComputer Science Department
Courant Institute of Mathematical Sciences
2
Agenda
• Summary of Previous Sessions• Java Platform Architectures• Java (Open Source) Development Tools • Java (Client) Applications• Java Support Technologies• Packaging Java Applications• Java Project Management• Readings• Class Project & Assignment #1b
2
3
Announcements
• Student Accounts on i5.nyu.edu• Extreme Java vs. eXtreme Programming (XP)• Homeworks & Projects Due Dates• Grader Assignments• Java IDEs• J2EE-Compliant Application Servers• Assignment #2
4
Summary of Previous Sessions
• Course Logistics, Structure and Objectives• Java Programming Language Features• Java Environment Limitations • Upcoming Features in “Tiger” 1.5• Model Driven Architectures for Java Systems• Java Enterprise Application Enabling• Agile Modeling & eXtreme Programming• Aspect-Oriented Programming & Refactoring• Java Application Performance Enhancement• Readings, Class Project, and Assignment #1a
3
5
Part I
Java Platform Architectures
6
Key Platform Features
• Resources• Packaging• Tools• Environment• Open Source Solutions on the Java Platform:
• http://jakarta.apache.org• e.g., “regexp” regular expression package, “log4j”
logging package, etc.
4
7
Java Platform Architectures
• Runtime Environment Architecture• Byte code verifier• Class loader• Runtime Execution Engine / optimizer• Security Manager (java.lang.SecurityManager) and API class files
• JVM enables type-safe reference casting, structured memory access (no pointer arithmetic), automatic garbage collection (can't explicitly free allocated memory), array bounds checking, checking references for null
• Native platform interface libraries • File Types
• Source code files (see http://java.sun.com/docs/codeconv/index.html) • Class files • Serialization files • Archive files • Manifest files
8
Java Virtual Machine Write Once Run Anywhere (WORA) Architecture
5
9
Java Virtual Machine (JVM)(continued)
• Byte Code Verifier • Class Loader (dynamic operation) • Runtime Execution Engine
• Performance bottlenecks: • Byte Code Execution, garbage collection, thread management,
dynamic operations (i.e., class loading, bounds checking, security measures, dynamic class loading, exception handling, reflection, and native method translation)
• Just- in- time compiler • Reduces byte-code interpretation and causes the execution
workload to shift to native compilation and caching of native methods.
• Precompiler
10
Pre Java 2 Security
7
13
Part II
Java Tools
14
Traditional Java Tools
• javac• jar• java• javadoc• jdb• appletviewer• javahelp
8
15
Java Interpreter• Software that implements the JVM and runs Java
application• Standalone or part of larger application
(e.g., browser) • Likely written in a native, compiled language • Loads Java class files and interprets the compiled byte-
code • Verifies compiled classes loaded from untrusted
sources • Can turn Java byte-code into native machine
instructions (dynamic/JIT compilation) • java [interpreter options] class name [program
arguments]
16
Using Java• Class should be fully qualified class name
(including class package if any)• Shouldn’t include “.class” file extension• Searches for the class in current class path
(-classpath option)• Looks for main() method
• main method signature: public static void main ( String [ ] myArgs )
• No need for argument count parameter (int argc = myArgs.length)
9
17
Class Path
• Piece of environment information providing a list of places to look for some resources
• CLASSPATH: list of locations that can be searched for packages containing Java class files
• Used by Java interpreter and compiler• CLASSPATH includes directory names or the names
of class archive files (.zip or .jar) • Use colon separator (UNIX), or semicolon separator
(DOS/Windows) • Default paths:
• .:$JDK_HOME/classes:$JDK_HOME/lib/classes.zip (UNIX) • .;%JDK_HOME%\classes;$%JDK_HOME%\lib\classes.zip (Windows systems)
18
Java Compiler
• Turns Java source code into a compiled class containing JVM byte-code
• .java -> .class • Allows one public class per file (file has same
name as class) • Storing the class files in alternate directory:
use -d option
10
19
Java IDEs• Eclipse• NetBeans• Sun ONE Studio• JBuilder• Visual Age for Java• VisualCafé• Codewarrior for Java• WebGain Studio• ModelJ• J2ME Wireless Toolkit • IntelliJ• etc.
20
Java IDEs – Selection Criteria• User Interface Ease of Use• IDE Customization Features• Code Editing Features• On-the-Fly Code Analysis• Code Style, Generation, Inspection• Refactoring Support• J2EE Support (JSP, XML, EJB, etc.)• Navigation• Search and Replace• JavaDoc Support• Local Version Control Support• Version Control System (VCS) Integrations• Compiler• Running/Debugging Support• Debugger• Other Integrated Tools• Open API• Written in Java / Available on All Platforms
11
21
Software Tools for XPhttp://jakarta.apache.org/cactus/http://www.junit.org/index.htm
• Cactus• Test framework for unit testing server-side java
code (Servlets, EJBs, Tag Libs, Filters, …)• Cactus uses JUnit and extends it• JUnit is a regression testing framework written by
Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java
• provides a packaged and simple mechanism based on Ant to automate server-side testing
22
Software Tools for XP(continued)
12
23
Part III
Java (Client) Applications
24
Type of Java Applications
• Standalone Java application • Runs independently
• Applet (embeddable program module) • Part of a larger application • Compatible with mainstream browsers
(Netscape, IE), and the Java appletviewer • JWS (Java Web Start) Applications
• A component model for deployable client software
• Subsumes the Applet component model
13
25
Java Web Start (JWS) Technology• See http://java.sun.com/products/javawebstart/• Applications do not require a browser once
downloaded • Files are cached on the client • Checks are performed with the web server to ensure
that the latest version of the application is being used (ZAC!)
• Built on top of Java 2 Security • Links point to JNLP files which syntax is defined as
part of a Java Community Process specification• http://java.sun.com/aboutJava/communityprocess/jsr/jsr_056_jnlp.html
26
JWS Application Launching
14
27
Sample JNLP File<?xml version="1.0" encoding="utf-8"?> <jnlp
spec="1.0+" codebase="http://javaweb.eng.com/jaws/apps" href="swingset2.jnlp"> <information>
<title>SwingSet2 Demo Application</title> <vendor>Sun Microsystems, Inc.</vendor> <homepage href="docs/help.html"/> <description>SwingSet2 Demo App</description><description kind="short">A demo</description> <icon href="images/swingset2.jpg"/> <offline-allowed/>
</information> <security>
<all-permissions/> </security> <resources>
<j2se version="1.3"/> <jar href="lib/SwingSet2.jar"/>
</resources> <application-desc main-class="SwingSet2"/> </jnlp>
28
JNLP Element to Launch an Applet
<applet-descdocumentBase="http://..." name="TimePilot" main-class="TimePilot.TimePilotApp" width="527" height="428"> <param name="key1" value="value1"/> <param name="key2" value="value2"/>
</applet-desc>
15
29
JNLP API
• BasicService • ClipboardService • DownloadService • FileOpenService • FileSaveService • PrintService • PersistenceService
30
Applet Tag
<applet attribute [attribute] …> [<param parameter>] [<param parameter>] …[HTML for non Java aware browsers] </applet>
16
31
Applet Tag (http://java.sun.com/j2se/1.4/jre/)
• attributes: width, height, code / object (serialized representation of applet) parameter: <param name=zone value=GMT>
• Applets can also be launched via the OBJECT or EMBED tag
32
Applet Plug-In • Needed for RSA signed applet verification • Provides enhanced applet debugging and
management features • Java Plug-in included as part of the JRE 1.4.1
• http://java.sun.com/products/plugin/
• JDK 1.3.1_01 was the first version to include Java Plug-in (1.3) software
• Consult the Java Plug-in documentation• http://java.sun.com/j2se/1.4/docs/guide/plugin/
• Using the HTML APPLET tag converter• http://java.sun.com/j2se/1.4/docs/guide/plugin/developer_guide/ht
ml_converter.html
17
33
Java 2 Plugin Architecture (http://java.sun.com/j2se/1.4/jre/)
34
Open JVM Interface (OJI)
• Allows any Sun-Compliant JVM (implementing OJI) to become the default JVM for a browser
• Supports Applet, Embed, and Object tags • Supports Java-JavaScript bidirectional
communication • Supports RSA signed applet verification
18
35
Applet Security • Java Plug-In Security Reference
• http://java.sun.com/j2se/1.4/docs/guide/security/index.html
• Security Features • RSA signed applet (jar signing in the JDK) • HTTPS (handled via browser) • Liveconnect for Java-JavaScript bidirectional
communication • Origin of HTML page must be same as that of applet • JavaScript must be signed and “UniversalBrowserRead”
permission must be enabled for JavaScript (default is local Java policy)
36
Java 2 Security
19
37
Java 2 Security (secure application distribution using Java cryptography API)
• Secure Application Distribution • Applications stored as a self-executing encrypted file • Only class file data is encrypted • Main executable file must be distinguishable
• Four Phases • Packaging • Encryption/Decryption • Loading • Execution
38
Part IV
Java Support Technologies
20
39
MDA
• OMG's MDA (Model-Driven Architecture) specification describes:• a PIM - platform-independent models (i.e. business
design)• PSMs - the mapping of a PIM to one or more
platform-specific model
• MDA => Model Once, Generate Everywhere• Review MDA presentations:
• http://www.io-software.com
40
MDA(continued)
UML Model (PIM)
AutoColor : StringDoor : IntegerEngine : Integer
<Auto><Color> Red </Color><Door> 4 </Door><Engine> 2 </Engine>
</Auto>
XMI Document (PSM)
XMI
<!Element Auto(Color*,Door*,Engine*)>
XMI DTD, Schema (PSM)
XM
I
MO
F
interface Auto{};
IDL, Java… (PSM)
Class Auto{public String color;public int Door;public int Engine;}
21
41
AspectJ – Locking Sample
01 aspect Lock {03 Data sharedDataInstance; 04 Lock( Data d ) { 05 sharedDataInstance = d; 06 } 08 introduce Lock Data.lock; 09 10 advise Data() { 11 static after { 12 thisObject.lock = new Lock( thisObject ); 13 } 14 } 17 }
• Creating a new aspect called lock with introduce and advise cross- cuts
42
AspectJ – Locking Sample(continued)
15 boolean locked = false; 16 17 advise Worker.perform*(..), AnotherWorker.perform*(..) { 18 before { 19 if ( thisObject.sharedDataInstace.lock.locked ) // enqueue, wait 20 thisObject.sharedDataInstace.lock.locked = true; 21 } 22 after { 23 thisObject.sharedDataInstace.lock.locked = false; 24 } 25 } 26 }
• Advising classes that work with the data (note that all the locking code is included in an aspect!)
22
43
Design Patterns and Refactoring• Refactoring improves code design without
adding new behavior• A design pattern is the description of a design
problem and of its solution, which comes with certain benefits and liabilities• See http://cs.wwc.edu/~aabyan/PATTERNS/
• Do design patterns drive refactoring or are design patterns discovered in the refactoring result?• See Refactoring to Patterns
http://www.industriallogic.com/papers/rtp016.pdf
44
Part V
Packaging Java Applications
Also See Session 2 Handout:
“How to Submit Projects in Zip or Jar Files”
23
45
Packaging: Java Archive (JAR) Files
• Can compress with ZLIB compression • Can use pkzip to create and maintain JAR
files • “jar” is the java archive utility • JAR file advantages: compression and
access time
46
JAR Utility
• See handout on how to submit projects using zip/jar
• jar -cvf jarFile path [path] […] • jar -tvf jarFile [path] […] • jar -xvf jarFile [path] […] • Alternatives: Mobile Object and Agents
GUI Jar utility (MOAJar), etc.
24
47
JAR Utility (continued)
• jar adds META-INF/MANIFEST.MF • packing list naming files along with
cryptographic checksums • jar -cvmf myManifest.mf spaceblaster.jar
spaceblaster • Use javakey to sign a JAR file (see digital
signature / certificate)
48
Java 2 Security(secure application distribution using Java cryptography API)
• Secure Application Distribution • Applications stored as a self-executing encrypted file • Only class file data is encrypted • Main executable file must be distinguishable
• Four Phases • Packaging • Encryption/Decryption • Loading • Execution
25
49
Part VI
Java Project Management
Also See Session 2 Sub-Topic 1 Presentation on:
“Java Project Management”
50
Java Project Management Approach
• Refer to the links on eXtreme Programming (see Session1 main slide set, and corresponding bullets under “Announcements on the course Web site).
• See “Java Tools for eXtreme Programming:• Mastering Open Source Tools, including Ant, Junit, and Cactus”
(Richard Hightower, Nicholas Lesiecki, ISBN: 0-471-20708-X, 11/2001)
• Regression testing framework: http://www.junit.org• Ant build tool and Cactus server-side unit testing:
http://www.apache.org• See Sub-Topic 1 presentation on Java Project
Management
27
53
XP Unit Testing
54
CMM & TSPhttp://www.sei.cmu.edu
• The Capability Maturity Model for Software (SW-CMM) is used by organization to guide their software process improvement efforts
• The Team Software ProcessSM (TSPSM) was designed to implement effective, high-maturity processes for project teams
• If all projects in an organization are using the TSP, does the organization exhibit the characteristics of high process maturity, as described in the SW-CMM?• http://www.sei.cmu.edu/pub/documents/02.reports/pdf/02tr008.pdf
28
55
SEI’s IDEALModel• IDEAL is an organizational improvement model
56
Part VII
Readings and Assignment
29
57
Assignment• Readings
• Mastering Java 2: Part 2 – Chapter 17 & Appendix B • Expert One-on-One: Chapter 2-4 as applicable• Selected readings mentioned in class or referenced in the handouts • Handouts posted on the course web site
• Assignment #1b: (submit report and implementation archive)• Implement a sample application and test it using Cactus
• Hint: use and extend the sample application provided in the Cactus distribution
• Extra Credit: • Implement and test the sample application using Cactus on top of a JVM
that supports behavioral reflection• Project Framework Setup
• Java Plug-in, Java Web Start, Apache’s Xerces/Xalan • J2SE 1.3.1, 1.4.0 or 1.4.1 (SDK)• IDE: Eclipse, NetBeans, Sun ONE Studio, JBuilder, Visual Age,
Visual Café, Codewarrior, WebGain Studio, Oracle JDeveloper, etc.• Editors: JCreator, UltraEdit, etc.