port scala to java version