translated example 5 to Java