Get the maximum amount of memory in JVM in Java

Description

The following code shows how to get the maximum amount of memory in JVM.

Example


// www  .j a v  a2 s. com
import java.text.DecimalFormat;

public class Main {
  public static void main(String[] args) {
    DecimalFormat df = new DecimalFormat("0.00");

    long maxMem = Runtime.getRuntime().maxMemory();
    System.out.println(df.format(maxMem / 1000000F) + " MB");

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization