Unification of Java examples

This is a replacement PR for #300 and #380.