Monday, October 6, 2014

On JavaOne 2014

Conference Summary

I mostly went to 5 kinds of sessions:
  • java 8 features (streams, lambdas)
  • java mechanics (garbage collecting, classloading)
  • groovy (traits, groovy & java 8, groovy futures)
  • code quality (DDD, code reviews, coding culture)
  • client server (websockets, rest)
The big takeaways included:
  • java 8 is really about enabling parallel execution.  Streams was the driving feature. Lambda expressions exist to support streams (and are incomplete) and type inferencing is required to support lambda expressions. Interface default methods exist to extend existing collections to support streams.  Method references are there to support streams.  Yes, the result is that you can do functional things in java 8, but the goal is parallelism not functional programming.  So there are gaps as well.
  • Groovy seems to be stuck.  They don’t seem to have finalized what they want to do about java 8 features.  And, since they already have many similar but not quite compatible features, they seem to be caught in a paradox.  Should they continue to try to make java programs compile mostly as-is in groovy?  Should they make their existing features work like the java 8 counterparts and potentially break backward compatibility?  Should they try to make both work and complicate the language semantics?  There doesn’t seem to be an easy answer.  And they didn’t have a compelling story around why you should continue to use groovy in the face of java 8.
  • I found that even though I knew about lambda expressions and streams, doing the tutorials really helped make all the blocks fit for me.  You may want to see if anyone is doing similar overviews at your jug back home.
  • The ability to mixin small bits of behavoir in the form of capabilities is an increasingly important design technique for object oriented systems. 

Session Summaries (TL;DR)

Collection and Reduction in the Steams API (Tutorial)

Stream: an abstraction representing zero or more values.  Streams can be sequential or parallel. Elements in a  sequential stream will be provided in sequence.  Elements in a parallel stream may be provided across different threads and different processors and will not appear in sequence. [This actually came from a subsequent presentation.)

Stream is organized as a pipeline
  • source
  • intermediate operations (return streams)
    • map, filter, sort
  • terminal operations (return to the non-stream world)
    • collectors - returns collections
    • reducers - returns values
Really designed to parallel-ize work

There are are large number of out-of-the box collectors such as toList(), joining(), toSet(), averaging(), toMap(), partitioningBy(), groupingBy(). (See

You can also write a custom collector.  A custom collector requires four functions:
  • supplier()         // returns function to create of a new result container
  • accumulator()  // returns function to add a new element into the result container
  • combiner()       // returns function to combine two result containers
  • finisher()          // returns function an optional final transform on the container
If you were going to create a collector that put results into a google guava immutable set:
public class ImmutableSetCollector<T>    implements Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>>

@Override public Supplier<ImmutableSet.Builder<T>> supplier() {
    return ImmutableSet::builder;

@Override public BiConsumer<ImmutableSet.Builder<T>, T> accumulator() {
    return (builder, t) -> builder.add(t);

@Override public BinaryOperator<ImmutableSet.Builder<T>> combiner() {
    return (left, right) -> {
        return left;

@Override public Function<ImmutableSet.Builder<T>, ImmutableSet<T>> finisher() {
    return ImmutableSet.Builder::build;

public Set<Characteristics> characteristics() {
    return EnumSet.of(Characteristics.UNORDERED);

There is an accumulator and a combiner so that the stream can be parallelized.

Rethinking API Design with Traits

I had actually seen the slides before going to the presentation.  But I still got a lot out of it.

Traits are a new feature in Groovy 2.3.

Solving the problem of how to create reusable bits of behavior that can be mixed in to objects/classes.  The previous attempt (@Mixin) had too many limitations.

Java 8 solves the same problem with default methods in interfaces.  Groovy traits can have state where interface default methods can’t.
trait FlyingAbility { 
    String fly() { "I'm flying!" }
class Bird implements FlyingAbility {} 
assert new Bird().fly() == "I'm flying!"
Think of traits as a way of expressing the capabilities of a class.

Can be mixed in at runtime.

Really pushing the idea of developing classes by having small bits of behavior that can be mixed together with some custom behavior into a class.

Some AST transformations are not trait compatible.

Reactive Streams with Rx

This presentation just blew past anything I was able to easily understand.

(And I took the coursera course Principles of Reactive Programming so I’ve actually used the scala version of Rx.)

After blowing though 8-10 hours of lecture material from Principles of Reactive Programming in the first 20 minutes or so, he discussed a variety of flow control mechanisms in the context of various netflix systems that had no meaning to me.

Unlocking the Magic of Monads in Java 8

At some point, somebody is going to figure out that the single worst way to describe monads is to start with the terminology that comes from Haskell. Explaining monads by writing pure (or return) and bind methods in java is insane.

I am always looking to deepen my understanding of monads and I am particularly interested how to use or implement the various common monads in Java 8.  And I suspect that if I study the code, I will probably learn something from it.  But you can’t actually do that in these sessions (more on that later), so I was disappointed.

Gradle: Harder, Better, Stronger, Faster

This ended up being little more than a commercial for using gradle over maven. It was also live coded so I can’t refer back to tell you anything more about this presentation.

Real-World RESTful Service Development Problems and Solutions (BoF)

Rolled through 44 slides in 45 minutes.  ‘Nuff said.

I’m sure there is good stuff in the slides somewhere….

JAX-RS REST Services and Angular.js: Tools for an Even Better Experience (BoF)

Kind of a throwaway for me. But it was the 8pm BoF so I didn’t think I was going to be too awake by then anyway.  The last half was live coding a demo which, aside from technical difficulties, was pretty interesting.

Did recommend swagger ( for rest api docs.

Also recommended using DTOs for the collecting REST data.  He worked on a bean mapper project Dozer but recommended a different mapper Orika (

Jump-Starting Lambda (Tutorial)

Lambda expressions mostly appear (but are not necessarily implemented as) syntactic sugar for anonymous inner classes.  So, instead of

void robocallEligibleDrivers() {
    robocallMatchingPersons(new PersonPredicate() {
        boolean test(Person p) {
            return p.getAge() >= 16;

You can write:

void robocallEligibleDrivers() {
    robocallMatchingPersons(p -> p.getAge() >= 16);

In order to implement lambda expressions, they also had to implement type inferencing. (Which they’ve enabled elsewhere as well.)

The type that is inferred for a lambda is a @FunctionalInterface or Single Abstract Method (SAM) interfaces.

There are a set of standard interfaces so defining your own interfaces is rarely necessary. The standard interfaces are:
interface Predicate<T> { boolean test(T t); }
interface Consumer<T> { void accept(T t); }
interface Function<T,R> {R apply(T t); }
Additional interfaces include:

Supplier<T> () ? T
UnaryOperator<T> T ? T
BinaryOperator<T> (T, T) ? T
BiFunction<T,U,R> (T, U) ? R

Note that when you write methods designed to be called with a lambda, you will use one of the types above as the parameter type:

So, for example, if you were going to write something like Jim’s withSession method in java 8, you would have a signature like:

static void withSession(SlingRepository slingRepository, String user, Consumer<Session> lambda) 

() -> 42                                                     // Need empty parens for a supplier
(int a) -> a + 1
int a -> a + 1                                            // Can omit parens for a single param 
int a -> { println(a + 1); return a + 1; }  // Surround multiple statements  
a -> { println(a + 1); return a + 1; }       // Types may be omitted if they can be inferred
(int a, int b) -> a + b                                // need parens with more than one param

Method references are shortcuts to use methods as lambda expressions:  There are 4 kinds of method references:

Integer::parseInt    // Reference to a static method taking the correct number of parameters
aPerson::toString  // Reference to an instance method of a particular object
Person::toString    // Unbound reference which will be bound by the lambda
String::new            // Constructor


Sources include stream() methods on collections, Stream.empty(), Stream.of(…)., Stream.generate(), Stream.iterate(), Stream.range(), various methods in File, String, Pattern. etc
Intermediate operations include forEach, map, filter, substream, limit, sorted, distinct, flatMap
Terminal operations include collect, toArray, count, anyMatch, findFirst

collect() takes a combining collector.  Some common collectors are toList(), joining(), toSet(), averaging(), toMap(), partitioningBy(), groupingBy()

String result = list.parallelStream()
                           .collect(joining(“, "));  // static import of Collections.*

Convert a sequential stream to parallel using .parallel().

Lambdas change the way you design libraries
Streams change the way you write applications

Method References will take over the world because you can code streams like:
String[] output =

A couple of specific notes from this presentation and other presentations:
  • Lambda expressions must not mutate source collection while stream executes
  • Lambda expressions do not have identity - you can’t use equals()
  • Lambda expressions are not closures.  Java already had closures which restricted access to instance variables to final.  Java 8 has a broader concept of effectively final but the bottom line is you can’t modify instance variables from inside the lambda expression
  • Lambda expressions can be chained:
    Callable<Runnable> c = () -> () -> { System.out.println("hi"); };
  • There is no direct support for currying. (Some people would say currying is a better alternative to closures.)

WebSocket in Enterprise Applications

Ended up being mostly about the Java API for WebSocket and its reference implementation.

Groovy in the Light of Java 8

Lots of minor reasons to continue to use groovy over Java 8 but it felt somewhat contrived:
  • closure parameter defaults
  • duck typing polymorphism
  • more elegant builder syntax
  • memoization
  • tail recursion
  • traits
  • compile time meta annotations
  • elvis operator
  • groovy on android
  • grails, ratpack, griffon, spock, geb, gradle, GPars, 
  • json support
Hasn’t really come to terms with java 8 features.

Coding Culture

You know those annoyingly always upbeat and relentlessly positive people? Hire only those people and then apply a whole bunch of new age techniques that fly in the face of everything we know about human nature.  When everybody is shiny and happy and all group hugging and refusing to do anything wrong in the “doacracy” then Peter Pan will sprinkle magic dust and miracles will happen.

Getting Started with MongoDB and Java

Turned out to be a live coding session that was mostly mostly derailed by detailed questions only vaguely related to the what the speaker was trying to do.

Using Type Annotations to Improve Code Quality

Mostly a discussion about how you could use the checker framework with the java 8 annotation extensions.  Some discussion about how it all might be incorporated into IDEs.  He did a nice demonstration using the regex checker to validate regular expressions at compile time.

Java Debugging

Garbage Collection Monitoring
  • might need to pay to use on servers?
  • -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
valgrind - OS level memory profiling

Heap Dump Analysis:
  • -xx:+HeapDumpOnOutOfMemoryError
  • jmap -dump:format=b
  • JConsole
IBM Memory Analyzer supports HotSpot dumps

Understanding Java Garbage Collection

Best presentation hands down. Here is a version of the presentation of the same talk at a previous conference.

I don’t think I can summarize it in any way that would do it justice.  A couple of notes though:
  • Garbage collection is better than you think it is. In particular, it really will find dead objects. Don’t try to help until you’ve proven the need to. "Trying to solve GC problems in application architecture is like throwing knives.”
  • GC stops for ~1 sec for each live GB
  • “Mostly" is the way vm vendors weasel out of GC guarantees.  Mostly means sometimes it isn’t (usually means a different fall back mechanism exists)
  • Generational Hypothesis: most objects die young
    (A consequence this is that most live objects in the system are actually not young)
    • Which means that you can optimize differently for young objects and old objects
  • The amount of empty memory in the heap is the dominant factor controlling the amount of GC work
    • Empty memory controls the frequency of pauses (if the collector performs any Stop-the-world operations)
    • Empty memory DOES NOT control pause times (only their frequency)
    • In Mark/Sweep/Compact collectors that pause for sweeping, more empty memory means less frequent but LARGER pauses
  • The Application Memory Wall - Application instances appear to be unable to make effective use of modern server memory capacities
    • Garbage Collection is a clear and dominant cause
    • [Virtually] All current commercial JVMs will exhibit a multi-second pause on a normally utilized 2-6GB heap.
      • It’s a question of “When” and “How often”, not “If”.
      • GC tuning only moves the “when” and the “how often” around
    • Monolithic stop-the-world operations are the cause of the current Application Memory Wall. Even if they are done “only a few times a day”

Think Async: Embrace and Get Addicted to the Asynchronicity of Java SE 8 and Java EE 7

Ended up being entirely J2EE focused.  Lots of code examples without real problems to motivate them.  Like why would I want an Asynchronous Servlet for example.

I think this topic slide pretty much summarizes the whole press:
  • Long present in JMS
    • To be used almost everywhere
  • Servlet 3.0/ 3.1
    • Asynchronous Servlets
    • Non blocking IO
  • JAX-RS 2.0
    • Server side
    • Client side
  • Asynchronous Session Beans
    • Server side
    • Client side
This was also the second presentation that mentioned but didn’t really describe Server-Sent Events which is a technology that could have some interesting uses on a site like

Programmatic WebSocket

This was a walkthrough of a sample program that used java websockets on both client and server.  The program built a custom document-oriented rpc on top of websockets using xdr encoding.  As a result, so much of this was custom code that it was hard to get anything out of the presentation.

DDD in a Rapidly Changing Organization

I wish I had the slides for this. After an intro of DDD and XP, he discussed some lessons learned in that environment.

There was some “DDD sales pitch” kind of stuff particularly about improving communication with the marketing team.

A lot of the lessons were around the problem that their marketing group changes terminology faster than they can change implementations.  Essentially marketing changes terminology because changing the name changes the perception. This caused a number of technical problems.  One example that that they had used mock heavy TDD, so making even simple changes to the model often required changing dozens of tests.  They they resisted making model changes. 

There was another lesson that they had been hurt by too strict adherence to DRY.

Do You Really Get Class Loaders?

This is the same presentation by a different presenter (from the same company):  (At least until you get to the end.)

Classloaders are organized hierarchically.  And, unless you arrange differently (which OSGI does), classes are loaded from the highest classloader possible.

A class has an identity of three things: a name, a package, and a classloader.

A couple of debugging tricks:
  • You can always get the classloader for an object (or class):
    Class klass = object.getClass();
    ClassLoader classloader = klass.getClassLoader()
  • You can cast a classloader to a URLClassLoader and use the getUrls method to get the paths in the classpath:
    URL[] urls = ((URLClassLoader) classloader).getUrls();
  • You can find which file a class was loaded from:
    URL url = klass.getResource(“/“ + klass.getName().replaceAll("\\.", "/") + ".class”);
  • Someone pointed out that you can also use the following:
When you leak a classloader, you leak all the classes it has loaded.

Groovy in 2014 and Beyond

Covered a lot of changes already in 2.3.

Groovy 2.4
  • New website
  • Groovy on Android
  • Macro module (maybe)
Groovy 3.0
  • Rewritten Meta-Object protocol
  • New antlr grammar
  • Java 8 language support (definitely not solidified)
  • Can they continue to make valid Java syntax work in groovy?
  • lambdas
  • method references
  • interface default methods

Want Code Quality? Just —The Art of the Code Review

You should do code reviews. And if anyone doesn’t like it, you should manipulate them into liking it.

Closing Keynote

Mostly and advertisement for Intel and various companies using Java.  But the technical part of the opening keynote apparently had run too long so the last half was moved here as well.  The interesting takeaway is that they are working on real value objects ( for java 10 which apparently will be a big change.  They are also redoing the module system ( in java 9.

Conference Review (Really TL;DR)

JavaOne is the tale of The Good, The Bad, and The Ugly

The Good

Several of the presentations were outstanding.  World class presentations by real experts. Even the presenters that weren’t great were certainly experts.  All-in-all the content was good and where it wasn’t I could probably have done a better job of picking sessions. (Yes, I’d like to learn websockets. I’m not sure why I thought I would be able to here.)

The Bad

The conference is too big which effects everything.  Long lines everywhere. Particularly for morning coffee and meals.  

Full sessions which required pre-registration to get in. Which means that you couldn’t get interesting in something and just jump into further sessions on the topic. Nor could you bail on a session and expect to be able to walk into another one.

No meal breaks? Really? All meals to go? Really? Long lines to get meals with no actual meal breaks? Really? I’m not doing the late night drinks at Duke’s Cafe - particularly when sessions run until 8:45 pm.  So meals are when I would expect to be able to meet my peers and swap stories. (Fortunately for me, it just gave me an excuse to run out to various take out places across various streets from the conference hotels which had shorter lines and better food. Definitely try the Filipino place across from the Hilton!)

The "appreciation event".  I didn’t come to the conference to be appreciated. I came to learn things. I really just feel like I missed out on what could have been a couple more interesting presentations. 

The Ugly

Some of the rooms were too small for the number of seats - and all the seats were full. Airplanes seats have more room. I had to leave the first tutorial at the half-way point because I was getting faint in the room. I had to organize the remainder of the conference to get to rooms when they opened entry to get aisle seats where I could make room.

No power. And no tables. I don’t know how they expect anyone to take any real kind of notes.

No slides.  As you can tell from the summaries above, I found some presentations really hard to follow.  If you are going to do a technical presentation, you need to provide slides so that I can glance back and forward to get my bearings when I start to get lost. (And all technical presentations have those moments where you start to get lost.)  And none of these “no more than one word per slide” presentations that provide no information on the slides. If this is a technical presentation, I expect 4-10 bullets per slide or code examples. Otherwise, you’re just Steve Jobs putting on a show. And whoever came up with live-coding should be shot. And then burned. And maybe stabbed for good measure.

My Net Promoter Score - maybe a 5.  Good content but, IMO, extremely poor logistics for a technical conference driven in part by the size of the conference.