# Presentation: 479105

## JavaOne 2000

**JavaOne 2000**

**Melissa Hess **(_[Melissa.Hess@AppNet.com](mailto:Melissa.Hess@AppNet.com)_), AppNet, Inc.
**Vince Pell **(_[Vince.Pell@AppNet.com](mailto:Vince.Pell@AppNet.com)_), AppNet, Inc.
**Jason Coleman **(_[Jason.Coleman@](mailto:Jason.Coleman@appnet.com)__[AppNet](mailto:Jason.Coleman@appnet.com)__[.com](mailto:Jason.Coleman@appnet.com)_), AppNet, Inc.

**TEAS**
**August 23, 2000**

## Agenda

**Conference Overview – Melissa Hess**
**Java 2D: Tips and Tricks– Vince Pell**
**Java Performance Tuning and the HotSpot VM – Jason Coleman**

## Conference Overview Agenda

**General Conference Information**
**Overview of Each Track**
**Session Breakdown**
**For Further Information**

## General Conference Info.

**5****th**** Annual JavaOne Conference June 6-9, 2000 Moscone Center San Francisco, CA**
**25,0000+ attendees**
**JavaOne Pavilion**
**10 parallel tracks**
**Sessions**** **
**11am – 6pm**
**Birds of a Feather (BOF)**
**Learn from the experiences of fellow developers**
**6am – 8am, 7pm – 12pm**
**300+ sessions and BOFS**

## General Conference Info Cont.

**Keynote**
**Steve Jobs states, "The biggest thing we're doing is we are going to bundle Java 2SE into every single copy of Mac OS X that we ship later on this year, the new version of the Mac operating system."**

## Overview of Each Track

**10 parallel tracks**
**Java 2 Platform, Standard Edition **
**Java Platform Optional Packages **
**Java 2 Platform, Enterprise Edition **
**Java 2 Platform, Micro Edition/Java Technology Devices **
**Jini Technology **
**Java Technology Technical Papers **
**Java Technology Program Modeling and Development Tools **
**Java Technology Today and Business Innovation**
**Java Technology Ideas -> Startup -> IPO **
**Java Technology + XML**

## Track 1: J2SE

**31 sessions**
**Most recent version is 1.3**
**Supported on Windows, Solaris (Sept.), Linux (Oct.)**
**Version 1.3.1 expected Q1 of 2001**
**Main objectives of 1.3**
**Performance**
**Web Deployment**
**Security**
**Enterprise Interoperability**

## Track 1 Cont.

**Default client VM is HotSpot 1.0**
**Client side performance**
**~40% reduction in startup time**
**~25% reduction in RAM usage**
**Swing Performance**
**JTable and JTree ~30% faster**
**3X faster raw scrolling**

## Track 1 Cont.

**HotSpot Server VM version 2.0**
**~30% faster **
**Windows = now**
**Solaris = September**
**Linux = October**
**Verion 1.4 aka “Merlin”**
**Reliability, Scalability, Interoperability, etc.**
**Targeted for 2001**

## Track 2: Java Optional Packages

**13 sessions**
**Jiro Technology**
**Enabling management infrastructure**
**Federated Beans (Dynamic Services)**
**Jini Technology**
**Java Cryptography API**
**Java Media API’s**

## Track 3: J2EE

**40 Sessions**
**Classroom type sessions**
**Overall J2EE Architecture**
**EJB and Persistance**
**Servlets**
**JavaServer Pages**
**Java Transaction API**

## Track 3 Cont.

**J2EE version 1.2 Dec. 1999**
**J2EE version 1.2.1 May 2000**
**J2EE version 1.3**
**First release June 2000**
**New Features**
**J2EE Connector Architecture**
**Java API for XML Parsing (JAXP)**
**EJB 2.0**
**JavaServer Pages 1.2**
**Java Servlet 2.3**

## Track 4: J2ME

**25 sessions**
**Communication to other devices handled by Jini**
**Java Card**
**J2ME interfaces to Java Card **
**Service Providers can use Java Card to recognize users**
**Java Card is a platform for executing code within a smart card**

## Track 4: Cont.

**K Virtual Machine**
**16 bit – 32 bit**
**10KB – 500 KB**
**For use in pagers, wireless phones, PDAs**
**PersonalJava **
**1****st**** Micro Edition Technology**
**Future PersonalJava 3.1**
**Based on Java 2 Platform Codebase**
**Expected early 2001**
**AWT based UI**
**2.0M Footprint**
**Fine-grained security**

## Track 5: Jini Technology

**20 sessions**
**Basic Jini Programming**
**Jini design philosophy**
**Security**
**Service UI’s**
**Helper services**
**Exposing EJB components as Jini services**
**Examples uses of Jini**
**Smart Spaces – “My Building Knows Where I am”**
**Lego Mindstorms Robots**

## Track 6: Technical Papers

**15 sessions**
**Core software engineering topics**
**Threads**
**Design patterns**
**Performance tuning**
**Improving design of existing code**

## Track 7: Program Modeling and Development Tools

**14 sessions**
**Web-based solutions**
**Dot-Com architectures**
**E-Commerce solutions**
**Remote debugging of server-side components**
**Comparison of Servlets, JavaServer Pages, and Active Server Pages**

## Track 8: Today and Business Innovation

**23 sessions**
**High performance web sites**
**Strategy for reuse of EJB components**
**Deploying Servlets and JavaServer Pages**
**Java and the securities industry**

## Track 9: Ideas -> Startup -> IPO

**3 sessions**
**Software patents**
**Lessons learned: Startups based on Java technology**

## Track 10: Java + XML

**13 sessions**
**~5 sessions talked about J2EE + XML**
**Parsing and processing XML Documents**
**XML data binding**

## Session Breakdown

**~200 sessions total**
**~40 sessions in the J2EE track**
**~20 sessions on J2EE not included in J2EE track**
**~1/3 of Sessions discussed J2EE**
**Other major concentration was network-centric**
**Jini**
**Jiro**
**Sun sees future of Java on server-side**

## For Further Information

_**[http://java.sun.com/](http://java.sun.com/javaone)**__**[javaone](http://java.sun.com/javaone)**_

## Java2D:  Tips and Tricks

**Java2D:  Tips and Tricks**

**Vince Pell **(vince.pell@Appnet.com), AppNet, Inc.

## Agenda

**A brief introduction to Java2D**
**A Demo illustrating some of the key features of Java2D**
**Simple tips and tricks to get the most out of Java2D**
**Fonts, Images, Drawing**

## What is Java2D

**Added in JDK 1.2**
**The Java 2D API provides **
**A uniform rendering model for display devices and printers **
**A wide range of geometric primitives, such as curves, rectangles, and ellipses and a mechanism for rendering virtually any geometric shape **
**Mechanisms for performing hit detection on shapes, text, and images **
**A compositing model that provides control over how overlapping objects are rendered **
**Enhanced color support to facilitate color management **
**Support for printing complex documents **

## What is Java2D (cont.)

**Java2D Packages:**
**New classes were added to packages:**
**java.awt**
**java.awt.image**
**Six new packages were added:**
**java.awt.color****	****	****	****•  java.awt.geom**
**java.awt.image.renderable****	****•  java.awt.font**
**com.sun.image.codec.jpeg****	****• java.awt.print**

## Creating a custom Component

**Extend JComponent and override ****paintComponent**
**In Swing, ****paint**** calls ****paintComponent****, ****paintBorder****, and ****paintChildren**** passing each a Graphics object to render on**
**Painting is executed on the Event Dispatching Thread (EDT)**
**Java2D introduces Graphics2D, an extension to Graphics.**
**To use Graphics2D, cast the Graphics object passed into the given paint method.**

## How do I control rendering?

**Rendering can be configured through the following Graphics2D properties:**
**Pen style  ****setStroke**
**Fill style  ****setPaint**
**Compositing style  ****setComposite**
**Transformation  ****setTransform**
**Clipping  ****setClip**
**Fonts  ****setFont**
**Rendering Hints  ****setRenderingHint**** **

## Coordinate Spaces

**User Coordinate Space**
**System independent**
**Floating point resolution**
**Drawing Origin is placed at the top left corner of the drawing space**
**Device Space**
**Corresponds to a particular hardware device**
**User Coordinate Space is transformed into Device Space**

## Java2D Demo

**Can be downloaded from: **
_**[http://java.sun.com/products/java-media/2D/samples/index.html](http://java.sun.com/products/java-media/2D/samples/index.html)**_
**Source code is included**

## Font Tips and Tricks

**Use Logical Fonts.  **
**Dialog, DialogInput, Monospaced, Serif, SansSerif, or Symbol**
**Platform independent**
**Preloaded (I think)**
**JDK 1.3 now has dynamic font loading which allows new Fonts to be loaded a runtime**
**File file = new File("Arial.ttf"); **
**FileInputStream fi = new FileInputStream(file); **
**Font font = Font.createFont(Font.TRUETYPE_FONT, fi);**** **

## Font Tips and Tricks (cont)

**Use ****deriveFont**** to create custom fonts**
**The size, style, and/or transformation of the font can be customized**
**Font font = new Font(“Serif”, Font.Plain, 1);**
**Font font24 = font.deriveFont(24.0f);**
**Font font24Ital = font24.deriveFont(Font.Italic);**
**AffineTransform trans = new AffineTransform();**
**trans.shear(0.2, 0);**
**Font font24Shear = font24.deriveFont(trans);**
**	****	****	**

## Image Tips and Tricks

**Use ****createImage**** instead of creating a BufferedImage when possible.**
**More opportunity for HW acceleration when rendering to and copying from the image**
**Format is optimized for the Screen**
**If you need a BufferedImage, ****createCompatableImage**** can be used to insure that the image type matches the screen format**
**A method of GraphicsConfiguration**

## Image Tips and Tricks (cont)

**When creating a BufferedImage avoid using an image types containing Alpha values (e.g. ****TYPE_INT_ARGB****)**
**Less memory consumption**
**Allows for use of faster rendering loops**

## Drawing Tips and Tricks

**Use GeneralPath as an alternative to drawing multiple shapes**
**GeneralPath allows for the creation of complex shapes. For example, a histogram can be created with one GeneralPath instead of many rectangles**
**The drawing calls of Graphics2D are expensive and should be minimized when possible**

## Draw Tips and Tricks (cont)

**Take advantage of clipping bounds when overriding ****paintComponent**
**Graphics has a ****getClipBounds**
**Minimizes the area that needs to be drawn**
**Achieve faster scrolling.  JScrollPane use ****BLIT_SCROLL_MODE**** by default in JDK1.3**
**Specify a clipping bounds when calling ****repaint**
**Otherwise, the entire component will be repainted**

## Draw Tips and Tricks (cont)

**In cases where extensive rendering is needed, consider prerendering to an offscreen image**
**Improves perceived performance**
**Allows more control on when rendering actually occurs (e.g. rendering may not be needed every time painting occurs)**

## Draw Tips and Tricks (cont)

**How to save a snap shot of your component**
**Assume ****this**** is a derivative of JComponent **
**Image img = createImage(getWidth(), getHeight());**
**paint(img.getGraphics());**
**File file = new File(“snap.jpg”);**
**FileOutputStream out = new FileOutputStream(file);**
**JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);**
**encoder.encode(img);**

## For Further Information

**The Java2D API Home Page**
_**[http://java.sun.com/products/java-media/2D/index.html](http://java.sun.com/products/java-media/2D/index.html)**_
**A Presentation from JavaOne**
_**[http://jsp.java.sun.com/javaone/javaone2000/event.jsp?eventId=864&trackId=1&eventType=TS](http://jsp.java.sun.com/javaone/javaone2000/event.jsp?eventId=864&trackId=1&eventType=TS)**_

## Java Performance Tuning

**Java Performance Tuning**
**and the HotSpot VM**

**Jason Coleman **(_[Jason.Coleman@AppNet.com](mailto:Jason.Coleman@AppNet.com)_), AppNet, Inc.

**8/23/00**

## Agenda

**What do we think is slow about Java?**
**Common attempts to gain performance.**
**What is actually slow about Java?**
**How **_**should**_** we try to gain performance?**
**What is HotSpot?**
**Why is it an improvement?**
**Habits to learn; habits to kick.**
**Using Java’s best features.**

## Defining My Terms

**What do I mean by “slow”?**
**Compared to what?**
**Poor responsiveness to user**
**Factors that hinder computational thru-put**
**What do I mean by “performance”?**
**Unless otherwise noted, I’m talking about execution speed**
**Memory usage is also a measure of performance**

## I Know Why Java Is Slow...

**“****86% of users expressed concern about the performance of Java technology-based applications.” —Developer.com**
**Object creation**
**Synchronization**
**Exception handling**
**Reflection**
**Method calls creating stack frames**

## How Do We Gain Performance?

**Legitimately**
**Caching reusable values**
**Object pooling**
**Object creation outside of for-loops**
**Questionably**
**Don’t use exceptions**
**Stay away from reflection**
**Manually “in-line” because method calls are expensive**

## Why Is Java Slow, Really?

**Bounds checking – every time you reference an object**
**Garbage collection – frequent pauses to manage memory**
**Interpreting byte code**
**Dynamic environment**
**Class loading**
**Type-safe casting**

## Proper Performance Tuning (1)

**Don’t!  (Well, not right away...)**
**Waste lots of time on code that doesn’t matter**
**Algorithms and Data Structures**
**The largest performance payoff**
**Beware:  searching and looping**

| Name | Add(x) | Remove(x) | Find(x) | Grow |
| --- | --- | --- | --- | --- |
| ArrayList | O(1) | O(n) | O(n) | O(n) |
| HashMap | O(1) | O(1) | O(1) | O(n) |

## Proper Performance Tuning (2)

**The 90/10 rule**
**90% of execution time will be spent running just 10% of your code**
**Use a profiler to find the hot spots**
**java –Xrunhprof ClassName**
**http://developer.java.sun.com/developer/technicalArticles/GUI/perfanal/**
**Optimize just the hot spots and you see an inordinate performance payoff**

## Java Performance Summary

**GC and Bounds-checking are expensive and you can’t fix them.**
**Careful selection of algorithms and data structures.**
**Focus your efforts on the hot spots.**

## Introduction to HotSpot

**HotSpot is the latest virtual machine from Sun**
**Standard with Java 1.3**
**Available for WinTel since late April**
**Two versions:**
**Client: fast start-up, responsive, small memory footprint**
**Server: flat-out execution speed**

## HotSpot Garbage Collector (1)

**Partial – doesn’t collect all memory at once**
**Nursery holds all new objects**
**“****Aged” objects are moved to heap**
**Different collection algorithms used**
**Typical GC pause < 10ms!**
**Accurate – no memory leaks**
**Handleless – provides 10% performance gain**
**Single-threaded – will not scale to MP systems**

## HotSpot Garbage Collector (2)

**Cooperative – Interpreter stops while GC runs**
**JIT-compiled code continues to execute**
**JNI code continues to execute**

## HotSpot JIT

**Compile the performance hot spots and optimize them aggressively.**
**Fewer compiled methods means smaller footprint.**
**JIT instructions are processor-specific, not platform-specific.**
**JIT in-lines all non-overloaded methods.**
**JIT can guess aggressively and then back off later; static compilers can’t.**

## Performance Summary

**GC and bounds checking are expensive**
**Fast GC (< 10ms pauses)**
**58% performance gain over 1.2.2 GC**
**Careful selection of algorithms and data structures**
**Generational GC**
**Separate collection algorithms**
**Focus efforts on the hot spots**
**Optimizing JIT**

## Benchmarking (1)

**From the SPECjvm98 FAQ: **
**Q3: What specific aspects of performance does SPECjvm98 measure?**
**A3: SPECjvm98 measures the time it takes to load the program, verify the class files, compile on the fly if a just-in-time (JIT) compiler is used, and execute the test...From the hardware perspective, the benchmark measures CPU (integer and floating-point), cache, memory, and other platform-specific hardware performance. **

## Benchmarking (2)

**Q18: What is the reference machine and why was it chosen? **
**A18: We selected the IBM PowerPC 604@133 as the reference machine...**
**JDK Version: JDK1.1.4 (JIT: off) **
**More info: **
**http://open.spec.org/osg/jvm98/qanda.html**

## Benchmarking (3)

## Performance Tips for HotSpot

**Don’t make your own object pool**
**HotSpot already does pooling of small objects**
**Creation/removal in Nursery vs. compaction in heap**
**Objects with expensive constructors may still benefit from pooling**
**Don’t finalize your objects**
**Doubles the life of the object**
**Use Weak References instead**

## Java’s Best Features

**Why use reflection/exceptions?**
**Software outlives hardware**
**What seems slow today won’t be slow forever**
**These features probably won’t end up in the “magical 10%”**
**These features enable some innovative designs and solve some difficult problems.**
**Clarity!**

## For Further Information

**Notes taken from these JavaOne presentations:**
- _Automatic Memory Management in the Java Programming Language_ – Steffen Grarup and Lars Bak
- _Java HotSpot Virtual Machine: The Foundation for Performance on the Java Platform_ -- Bill Pataky
- _High- Performance Computing With Java Technology_ – Stefan Nilsson
- _Java Platform Performance_ – Steve Wilson and Jeff Kesselman
**Slides for all JavaOne presentations available at: **http://jsp.java.sun.com/javaone/javaone2000/tracks.jsp