Runtime the class class mainly represents the environment in which the application runs.
GetRuntime () returns the running environment object for the current application.
the EXEC (String command) executes the corresponding executable file according to the specified path.
freememory () returns the amount of idle memory in the Java virtual machine. In bytes
MaxMemory () returns the maximum amount of memory that the Java virtual machine is attempting to use.
totalmemory () returns the total amount of memory in the Java virtual machine
Import Java.io.ioexception;public class Demo03 {public static void main (string[] args) throws IOException, Interruptedexc eption {Runtime runtime = Runtime.getruntime (); Process process = Runtime.exec ("C:\\windows\\notepad.exe"); Thread.Sleep (3000); Let the current program stop for 3 seconds. Process.destroy (); SYSTEM.OUT.PRINTLN ("The amount of idle memory in the Java Virtual machine. "+runtime.freememory ()); SYSTEM.OUT.PRINTLN ("Maximum amount of memory that the Java virtual machine is trying to use:" + runtime.maxmemory ()); System.out.println ("Returns the total amount of memory in the Java virtual machine:" + runtime.totalmemory ());}}
Execution results
The amount of idle memory in the Java Virtual machine. 124864272Java virtual machine attempts to use the maximum amount of memory: 1879048192 returns the total RAM in the Java virtual machine: 126877696
Runtime of Java