java program translated to javascript