Get the total amount of memory in the Java virtual machine in Java
Description
The following code shows how to get the total amount of memory in the Java virtual machine.
Example
//w w w . j a va 2s . com
import java.text.DecimalFormat;
public class Main {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.00");
long totalMem = Runtime.getRuntime().totalMemory();
System.out.println(df.format(totalMem / 1000000F) + " MB");
}
}
The code above generates the following result.