In the thrown exception you can see the line number of the problem. For the above example, the thrown exception is like this:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at SomePackage.SomeClass.main(SomeClass.java:14)
For this example the problem has occured in line 14. By this way you can understand when the overflow has occured and debugging becomes easier. If you are sure that there is no problem with the code, then you can change the java heap space via command line:
C:\> java -Xmx256m -jar SomeApp.jar
This command increases the java heap space to 256MB. By default java heap space is 128 MB.