P304: Added Java solution.