The Runtime
class has methods that interface and interact with the application’s runtime environment.
The totalMemory()
method of the Runtime
class is used to retrieve the total memory available in the Java Virtual Machine (JVM). The value returned by this method is in bytes.
public native long totalMemory()
This method returns the total memory available to the JVM.
public class Main { public static void main(String[] args){ Runtime currentRuntime = Runtime.getRuntime(); System.out.println("Runtime.totalMemory() = " + currentRuntime.totalMemory() + " bytes"); } }
getRuntime()
method of the Runtime
class.totalMemory()
method on the currentRuntime
retrieved in line 4.RELATED TAGS
CONTRIBUTOR
View all Courses