Home / Java Patterns and Pitfalls     frequal.com

JavaOne 2010 Summary

Project Coin

  • Coin: Small language changes.
  • No new keywords.
  • New "diamond" syntax: List<List<String>> list = new ArrayList<>();
  • Compiler desugars try-with-resources into nested try-finally's
  • Coin team picked "complex" type inference strategy (include constructor params) since it made implementation easier.
  • Change requiring most effort: try-with-resources
  • Change with most design complexity: Diamond
  • Change requiring most syntax change: try-with-resources

Performance: Java versus C

  • Summary: "It Depends"
  • Debian language shootout compares different algorithms, not languages, so it isn't a fair comparison.
  • Virtual call to a function with a constant return: Java wins since it optimizes to final value, C++ must make call.

Swing Tips and Tricks

  • Main rule: access Swing components only on Event Dispatch Thread (EDT)
  • Break the main rule and you'll get exceptions and painting artifacts.
  • However, put expensive operations on EDT and app will become sluggish.
  • Use SwingWorker to offload slow tasks. Be sure to catch exceptions in doInBackground() so they don't get lost.
  • Use EventListenerList when implementing an Observer.
  • Use EDTHangMonitor to find EDT hogs
  • Tricks:
    • Cache images instead of reloading.
    • Precompute displays/images rather than doing it on the fly.
    • Change push to pull: Refresh at fixed intervals instead of faster data change rate.
    • Force on OpenGL and other hardware acceleration via system properties.

Java 2D

  • Java 2D: Widely-used API for drawing 2D shapes, text, colors, and images.
  • Has concepts and API similar to PostScript.
  • Can us multithreaded rendering if you have a BufferedImage. Each thread gets its own Graphics and writes to different sections.
  • Use Logical Fonts (SanSerif, Dialog, etc.)
  • Logical fonts support multiple languages.
  • Graphics.setCompoiste() lets you combine the new shape with the existing surface using alpha blending. Allows fade in/out effects.
  • For animation, use Swing Timer. It calls you back on the EDT so you can call into Swing components.
  • The timing framewoek on java.net makes animation easy.
  • Java2D is high performance and cross-platform.

User Experience

  • Subjectively attractive interfaces are preferred even if functionally equivalent.
  • Read O'Reilly's Effective UI.

JPA Best Practices

  • Create a separate Primary Key class instead of an embedded PK.
  • @Id is now allowed on @ManyToOne relations.
  • In JPA 2.0, @Access(PROPERTY) allows overriding getter/setter to customize value from what is stored. Unit conversions, for example.
  • Avoid Embeddeded objects. They can't be queried. Make them entities instead.
  • Use explicit, named join instead of long dotted expression
  • If your queries don't care about prior writes, the use COMMIT flush mode.
  • Use TypedQuery, it lets you specify the return cast and avoid casting.
  • Use criteria queries when you need to construct queries dynamically.
  • Parameters are faster than composing queries with strings.
  • Prefer named parameters to positional ones.
  • Use detach(obj) when you need to remove one object from the transaction without affecting all others.
  • Prefer optimistic locking to pessimistic locking, unless there is tons of contentions and retries.

Project Jigsaw

  • Jigsaw: Modules for Java. Bundled, versioned, packaged collections of related Java classes.
  • No more classpath, dependencies are recorded in the source code.
  • Modules are used all of the way down into the VM and launcher itself.
  • Modules will now be installed, so install-time optimizations can be performed. Preliminary performance improvement in parentheses.
    • Pre-verification: Do classfile verification at install time, flag as verified, no need to re-verify each run. (10-20%)
    • Profiled list of used classes used to generate one big app-sepcific file, loaded automatically at next startup. (10-30%)
    • Class data sharing: Convert classes to VM-optimized in-memory format for fast loading without translation. (10-20%)
  • A new module-info.java file describes the module
    • Flexible version info can go on the module itself and in the lists of its requirements.
    • Encapsulation and hiding are allowed via "permits" flag, which allows only selected modules to see this one, for internal modules.
  • JMOD format (.jmod) will be the primary, optimized package format for Java Modules.
  • JAR format with extra metainfo will be an alternative format, called Modular JAR.
  • Run an app in a module com.foo.app looking for modules in the directory mlib. All dependencies are loaded from mlib automatically.
    java -L mlib -m com.foo.app
  • Repositories will be places to find modules that aren't available in the specified (-L) directory. There will be a Sun-standard repository with lots of modules, so in many cases you won't have to pre-bundle lots of modules, they can be fetched from the central repo.
  • Class-path based apps will work for the most part, but some will break after modularization if they:
    • Depend on internals of the JDK or use unsupported APIs (import sun.*).
    • Directly look at or open rt.jar or tools.jar (rare).
    • Use the -Xbootclasspath command-line parameter.
  • Maven interoperability is planned.
    • You will be able to add a Maven Repo as a module repo.
    • A POM file has enough info to synthesize a module-info.java file, so it should be possible to auto-generate a module from a dependency in a Maven repo.
  • Reverse-DNS may not be retained as a requirement for module names. That is under discussion.
  • The order of "jmod install" invocations is important currently. In today's builds, you must install dependencies in repo first. This is a topic of debate and may change.


LambdaJ is a library for concisely expressing operations on collections. For example, creating a list of top speeds from a collection of cars, which would take 4-5 lines using a for loop, takes one with LambdaJ:

List speeds = extract(cars, on(Car.class).getSpeed());

Good stats were presented (min/max/avg) comparing LambdaJ against iterative code. The framework added 200% overhead, a reasonable price for concise code operating on small to medium datasets.

Java Technical Keynote

  • Java SE
    • The for loop of today executes on just one processor. In the future, new syntax will allow you to specify the conditions and operations to be done in the loop, and the VM/library will parallelize across available processors.
    • Project Lambda: Lambda Expressions built-in to the language. Proposed predicate syntax for example of checking for 2010 graduates:
      #{Student s -> s.gradYear == 2010}
    • HotSpot versus JRockit: HotSpot has been picked as the JVM of the future, primarily since more engineers were familiar with it.
  • Java EE
    • In EE6, web.xml is now optional. Moving away from XML mandatory configuration.
    • When JDK8 arrives with module support, the server will be able to download dependencies from repositories, no need to bundle all JARs into the WAR any more.
  • Java ME
    • Java ME and Web interop will be bidirectional:
      • Java ME code will be able to call to WS
      • Java ME GUI will be able to embed an HTML View in 2011 (JSR 290)
      • JavaScript on web pages will be able to call Java ME classes. (Release TBD)

Oracle Develop Keynote

  • Rally
    • Cut your Batch Size: Some people release to production multiple times per day.
    • Used JavaFX to consume Rally WS and produce new UI with live charts and other rich UI features.
  • Rich Enterprise Applications
    • "Native Mobile": an app written with the primary UI toolkit for a mobile device.
    • ADF Mobile Client is in Developer Preview.
      • It renders an ADF app to a native mobile client.
      • Stores local changes in an SQLite or Berkeley DB.
    • Showed some sort of Excel integration, but on windows only.

REST Security

  • Service Providers should:
    • Prevent up-front threats:
      • Use a firewall to limit entry points.
      • Have a plan to limit the effect of DoS attacks.
    • Control Access
      • Require authentication on each request.
      • Authorize application access using authenticated credentials.
      • Log access.
    • Propgate Identity across service calls.
  • A tool to test regular expressions
  • Images can come from anywhere, even on a page normally restricted to a single host. So an attacker who can inject JavaScript can export data from your page to an image request on their server.
  • If you have a customer-facing web server that talks to internal services, it should pass along authentication info to the called service.
  • For data integrity, use SSL
  • For Confidentiality, use SSL on the wire, and store sensitive information encrypted on-disk.

ADF on Mobile

  • ADF Mobile for JDeveloper is trying to address fragmentation in the Mobile Market.
  • Users are demanding device native (mobile native) interfaces on different OSes and form factors.
  • Two ways in ADF Mobile:
    • ADF Mobile Browser: web-served UI that automatically tunes itself to the mobile browser, from Opera to WebKit (Android/iPhone).
    • ADF Mobile Client: native client with proper LAF, access to contacts, etc. Works when offline.
  • ADF Mobile Client platform support:
    • Blackberry now
    • Android 2011
    • Long-term (sounds very long-term):
      • iPhone
      • Symbian
  • Mobile Client
    • Is beta-quality right now, some labels weren't line up in the demo properly.
    • Uses Panels and Layouts, like Swing, to allow stretching and shrinking for different resolutions and form factors.
    • Provided missing Java libraries on all platforms (Android, BB). However, all of this requires a license for each user, approximately $5/named user.
    • A few things do need to be customized per-platform:
      • Icons
      • Signing

Java Keynote

  • LiveScribe pen demoed
    • Pen records what you write and say
    • Can playback what was said at any point from what you wrote by tapping on the page
    • Can recognize text and translate it
    • Has apps that recognize symbols written on the page
    • Can sync, generate PDF, and e-mail
  • Volkswagen demoed a driverless car that can drive up Pike's Peak at 3x the speed limit
    • VNC client used to show their Swing app on mobile devices.
Oracle Linux has the Nimbus theme now.

JavaFX 2.0

  • Java is the primary language for JavaFX 2.0.
  • All APIs will be available in Java (and hence in any JVM langauge).
  • Embedded HTML with seamless DOM integration
  • Birdirectional HTML: Embed HTML in JavaFX, JavaFX in HTML
  • 2D and 3D graphics will fast HW acceleration
  • Full Swing integraion: Will be able to embed in Swing in a later release.
  • 2011 release dates:
    • EA in Q1
    • GA in Q3
  • JavaFX binding to replace JSR-295 bean binding
  • JavaFX script is dead

Last modified on 24 Sep 2010 by AO

Copyright © 2016 Andrew Oliver