Optimized Java code