Java Tutorials - Herong's Tutorial Examples - v8.22, by Herong Yang
Runtime.getRuntime() - Getting the Runtime Object
This section describes the system Runtime object and the Runtime.getRuntime() method to get it from the JVM.
When a Java application program is running inside a JVM, the JVM offers an instance of the Runtime class to the program. The Java program can use this Runtime instance to interact with the JVM and the supporting operating system.
There are several interesting types of methods available on the Runtime instance:
The Runtime class is a special class. It represents the run time environment of the Java application program running inside the JVM. You can not create a new instance of Runtime class in your application program. You can only get the instance created by the JVM for your application program by calling the Runtime.getRuntime() method.
So, the following code is wrong:
Runtime rt = new Runtime(); rt.gc();
The following code is correct:
Runtime rt = Runtime.getRuntime(); rt.gc();
Table of Contents
Execution Process, Entry Point, Input and Output
Primitive Data Types and Literals
Bits, Bytes, Bitwise and Shift Operations
Managing Bit Strings in Byte Arrays
Reference Data Types and Variables
StringBuffer - The String Buffer Class
►System Properties and Runtime Object Methods
System.setProperty() - Setting Your Own Properties
►Runtime.getRuntime() - Getting the Runtime Object
freeMemory() - Getting JVM Free Memory Information
Calculating Memory Usage of an Array
exec() - Executing Operating System Commands
Generic Classes and Parameterized Types
Generic Methods and Type Inference
Lambda Expressions and Method References
Java Modules - Java Package Aggregation
Execution Threads and Multi-Threading Java Programs
ThreadGroup Class and "system" ThreadGroup Tree
Synchronization Technique and Synchronized Code Blocks
Deadlock Condition Example Programs
Garbage Collection and the gc() Method
Assert Statements and -ea" Option