Determining the amount of memory available

Try the Runtime class. It contains the methods totalMemory and freeMemory. totalMemory returns the total amount of memory available to the Virtual Machine.

public class Main
{
   public static void main(String []args) throws Exception {
      long tm = Runtime.getRuntime().totalMemory();
      long fm = Runtime.getRuntime().freeMemory();
 
      System.out.println("Total memory: " + tm);
      System.out.println("Free memory: " + fm);
   }
}

Output in my case:

Total memory: 3346424
Free memory: 1131184

To change the amount of total heap memory available, you can specify so as an argument to Java:

java -Xms10M Main

Outputs:

Total memory: 10485752
Free memory: 7118616