The Java Virtual Machine (JVM) is the execution component of the Java Runtime Environment (JRE) that interprets and executes the byte code stores in a Java class. Within the Java Virtual Machine is a notional idea of the Java heap which is where objects created in a Java class reside in memory during the program’s execution.
When an object is done being used by the executing program, the Java Garbage Collector frees the memory in the Java Heap used by the object. If your java program requires an extensive use of memory and you do not increase the default Java Heap size, then your program can fail on a “out of memory” Java exception.
Step1 Open the command or DOS prompt on your computer. To open the prompt, select the “Start” menu and type “command” in the search text field followed by the “Enter” key.
Step 2 Change the DOS directory to the location of the Java program you are going to execute with the larger Java Heap size. To do this, type “cd ” followed by the fully qualified directory path of the class files. An example of this is: “cd c:\myjavafiles”.
Step 3 Change the max Java Heap size to 128 megabytes through the use of command line arguments on the Java Virtual Machine invocation. To do this, type the following command at the DOS prompt followed by the “Enter” key:
java –Xmx128m YourClassNameHere
Step 4 Exit the Java program run in Step 3. Re-run the Java application setting an initial default Java Heap size of 32 megabytes (MB) with the ability to increase the heap size to 128 MB if required by typing the following command at the DOS prompt followed by the “Enter” key:
java -Xms32m -Xmx128m YourClassNameHere