Extreme Java G22.3033-006
Session 2 – Main Theme Java Tools and Software Engineering Techniques
Dr. Jean-Claude Franchitti
New York University Computer Science Department Courant Institute of Mathematical Sciences
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
1 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
3
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
4
2 Part I
Java Platform Architectures
5
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.
6
3 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
7
Java Virtual Machine Write Once Run Anywhere (WORA) Architecture
8
4 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 9
Pre Java 2 Security
10
5 Java 2 Security
11
Java 2 Security
12
6 Part II
Java Tools
13
Traditional Java Tools
• javac •jar •java • javadoc •jdb • appletviewer • javahelp
14
7 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] 15
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)
16
8 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)
17
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
18
9 Java IDEs
•Eclipse • NetBeans • Sun ONE Studio • JBuilder • Visual Age for Java • VisualCafé • Codewarrior for Java • WebGain Studio • ModelJ • J2ME Wireless Toolkit • IntelliJ
•etc. 19
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 20
10 Software Tools for XP http://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
21
Software Tools for XP (continued)
22
11 Part III
Java (Client) Applications
23
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 24
12 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 25
JWS Application Launching
26
13 Sample JNLP File
JNLP Element to Launch an Applet
28
14 JNLP API
• BasicService • ClipboardService • DownloadService • FileOpenService • FileSaveService • PrintService • PersistenceService
29
Applet Tag
30
15 Applet Tag
(http://java.sun.com/j2se/1.4/jre/)
• attributes: width, height, code / object (serialized representation of applet) parameter: • Applets can also be launched via the OBJECT or EMBED tag
31
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 32
16 Java 2 Plugin Architecture (http://java.sun.com/j2se/1.4/jre/)
33
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
34
17 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)
35
Java 2 Security
36
18 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 37
Part IV
Java Support Technologies
38
19 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
39
MDA (continued) UML Model (PIM) XMI Document (PSM)
Auto
20 AspectJ – Locking Sample
• Creating a new aspect called lock with introduce and advise cross-cuts 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 } 41
AspectJ – Locking Sample (continued) • Advising classes that work with the data (note that all the locking code is included in an aspect!) 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 } 42
21 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 43
Part V
Packaging Java Applications
Also See Session 2 Handout:
“How to Submit Projects in Zip or Jar Files”
44
22 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
45
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.
46
23 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)
47
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 48
24 Part VI
Java Project Management
Also See Session 2 Sub-Topic 1 Presentation on:
“Java Project Management”
49
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
50
25 eXtreme Programming (XP) Map http://www.extremeprogramming.org
51
XP Iteration Planning
52
26 XP Unit Testing
53
CMM & TSP http://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 54
27 SEI’s IDEALModel
• IDEAL is an organizational improvement model
55
Part VII
Readings and Assignment
56
28 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. 57
29