java.lang.OutOfMemoryError

The OutOfMemoryError occurs when the 'Maximum Heap Size' for your application is reached.

The following code will throw the OutOfMemoryError:
Collection aCollection = new ArrayList();
while(true) {
    aCollection.add(new String("hopla"));
}


The output for this code will be:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

How to solve this?
First of all check if your application has no 'memory leaks'. These can occur by holding objects in memory that you no longer need.
The standard heap size is 128MB. You can increase the heap using the Xms and Xmx attributes while launching your application:
java -Xms<initial heap size> -Xmx<maximum heap size> If you don't specify these arguments during launch the following values are used: java -Xms32m -Xmx128m

These two parameters can influence the performance of your application.