rewrite using Java