Java rewrite