a java implementation