Setting the initial and maximum heap size

You can use the Java command line parameters -mxX and -msX:
from Sun’s site:

-mxx
          Sets the maximum size of the memory allocation pool (the garbage collected heap) to x. The default is 16 megabytes of memory. x must be
          greater than or equal to 1000 bytes. The maximum memory size must be greater than or equal to the startup memory size (specified with the -ms
          option, default 16 megabytes). 
 
          By default, x is measured in bytes. You can specify x in either kilobytes or megabytes by appending the letter "k" for kilobytes or the letter "m"
          for megabytes. 
 
-msx 
          Sets the startup size of the memory allocation pool (the garbage collected heap) to x. The default is 1 megabyte of memory. x must be > 1000
          bytes. The startup memory size must be less than or equal to the maximum memory size (specified with the -mx option, default 16 megabytes). 
 
          By default, x is measured in bytes. You can specify x in either kilobytes or megabytes by appending the letter "k" for kilobytes or the letter "m"
          for megabytes. 

Eg.

java -ms32000k -mx32000k TestProgram