Use primitive data types instead of objects You can speed up applications that manage large amounts of numeric data by using primitive data types rather than objects. Especially when working with large arrays that may need to be sorted or iterated through quickly, primitives can provide a 200-300 percent speed increase over objects. Java VM implementations keep primitive data types like int very close to the underlying native system representation. These data types use much less memory than objects, are amenable to optimized methods like System.arraycopy, and are faster to evaluate than object types like Integer. Objects are inherently more flexible than primitives but have relatively high overhead requirements. A judicious use of primitives in performance-sensitive areas can give applications a relatively painless boost in efficiency. This code snippet demonstrates the advantage of using doubles instead of Doubles when sorting an array: import java.util.*; public class PrimitiveSpeedTest { public static void main(String[] args) { double[] dblarr = new double[10000]; for (int i=0; i
Hosted by www.Geocities.ws

1