optimize java code