Unification of Java examples

This is a replacement PR for #300, which I am closing now.