Well , you all don't give a complete answer.
@DAVC , let me explain you.
There are 2 reasons why your java runs out of memory.
Your java application has a memory leak or your Java application needs a lot of memory . More than 128 MB by default. So , java heap size can be increased using the following parameters :
java -Xms<initial heap size> -Xmx<maximum heap size>
You can set this in the java control panel or in the command line . Depending on the enviroment you run your application.
This is what you must do in order to solve this problem .
Good luck.