Converted JS to Java