solving problems when converting to Java