In this example we will show how to get amount of total memory in the Java Virtual Machine(JVM) with totalMemory method of Runtime class.
Source Code
package com.beginner.examples;
public class TotalMemoryExample {
public static void main(String[] args){
Runtime run = Runtime.getRuntime();
//get totalMemory
long memory = run.totalMemory();
System.out.println(memory + " bytes total in JVM.");
}
}
Output:
128974848 bytes total in JVM.