Most JVMs have an option to set the maximum heap size e.g.
-Xmx64m
-Xmx8g
In Java 1.0 to 1.2 you could use
-mx64m
and this is still available on some JVMs for backward compatibility (E.g. Oracle JVM).
There are a few common misconceptions about this setting.
-Xms
sets the initial heap size.The amount of memory used at run time can change dynamically.