I got runtime error as "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ". How can I solve this problem? Can anyone explain me why this problem occurs? Thanks in advance.
I would guess you're using recursion...maybe?
Recursion can cause this, and so can many other things. Explain what your program is doing, please.
Recursion causes StackOverflow, not often OutOfMemory :)
You're probably trying to read in some very large file or otherwise reserving a lot of memory.
Figure out where you are doing that and try to find a way around it.
Just adding to what the two above stated...
Look to see if you're creating lots of new objects. Memory Exceptions ocure when your java application uses all of its allowed memory. I believe the default setting is 64megs. My guess is that inside a loop (if, while, or a recursive loop) there are new objects being created. While this isn't bad, it could be the source of the problem.
I thnk you will have to use -Xms and -Xmx as such
java -Xms<initial heap size> -Xmx<maximum heap size>
You best bet is make your own mini application launcher to get around this problem.
Unless there's a definite limit to the amount of memory the application will claim (so no errors or unforeseen conditions causing infinite loops for example) that will only delay the inevitable :)