examples in scala and java copied from James Iry's blog