Java.lang.Runtime.getRuntime() 方法
描述
java.lang.Runtime.getRuntime() 方法返回与当前 Java 应用程序关联的运行时对象。 Runtime 类的大部分方法都是实例方法,必须针对当前运行时对象调用。
声明
以下是 java.lang.Runtime.getRuntime() 方法的声明。
public static Runtime getRuntime()
参数
NA
返回值
此方法返回与当前 Java 应用程序关联的 Runtime 对象。
异常
NA
示例
下面的例子展示了 lang.Runtime.getRuntime() 方法的使用。
package com.tutorialspoint;
public class RuntimeDemo {
public static void main(String[] args) {
// print when the program starts
System.out.println("Program starting...");
// get the current runtime assosiated with this process
Runtime run = Runtime.getRuntime();
// print the current free memory for this runtime
System.out.println("" + run.freeMemory());
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Program starting... 62780856

