rewrite in java