You can dramatically improve application performance by reducing the amount of garbage collection performed during execution. The following practices can also increase performance:
Increase the initial heap size from the 1 MByte default with:
java -ms number . java -mx number .
The default maximum heap size is 16 MBytes.
Find areas where too much memory is being used with:
Take size into account when allocating arrays (for instance, if short is big enough, use it instead of int).
Avoid allocating objects in loops (readLine() is a common example)