Get the memory in your Java virtual machine

ReturnMethodSummary
longtotalMemory()Returns the total amount of memory in the Java virtual machine.
longfreeMemory()Returns the amount of free memory in the Java Virtual Machine.
longmaxMemory()Returns the maximum amount of memory that the Java virtual machine will attempt to use.

public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();
    System.out.println("Total memory:"+runtime.totalMemory());
    System.out.println("Free memory:"+runtime.freeMemory());
    System.out.println("Max memory:"+runtime.maxMemory());
  }
}

The output:


Total memory:5177344
Free memory:4991032
Max memory:66650112
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.