OutOfMemoryError in Java

How to deal if a program terminates abruptly with an OutOfMemoryError in Java projects ?
1 answer

Increase the VM memory size

- Find out the issue for the high memory consumption with debugging the program, try to fix or optimize that construct.
- Increase the max. heap size with a VM arg (the default is between 64MB to 1GB), for example use -Xmx2048m