Runtime
class in Java?The Runtime
class has methods that interface and interact with the environment in which the application is run.
maxMemory()
methodThe maxMemory()
method of the Runtime
class is used to retrieve the maximum memory that the Java Runtime Environment (JVM) will attempt to use. This method returns a value in bytes.
public native long maxMemory()
This method returns the maximum memory that the JVM will attempt to use.
public class Main {public static void main(String[] args){Runtime currentRuntime = Runtime.getRuntime();System.out.println("Runtime.maxMemory() = " + currentRuntime.maxMemory() + " bytes");}}
getRuntime()
method of the Runtime
class.maxMemory()
method on the current runtime, which was retrieved in line 4.