What is the importance of Runtime class in Java?

The java.lang.Runtime class is a subclass of Object class, can provide access to various information about the environment in which a program is running. The Java run-time environment creates a single instance of this class that is associated with a program. The Runtime class does not have any public constructors, so a program cannot create its own instances of the class. A program must call the getRuntime() method to get a reference to the current Runtime object. The important methods of Runtime class are addShutdownHook(), exec(), exit(), freeMemory(), gc(), halt() and load().


public class Runtime extends Object


public class RuntimeTest {
   static class Message extends Thread {
      public void run() {
         System.out.println(" Exit");
   public static void main(String[] args) {
      try {
         Runtime.getRuntime().addShutdownHook(new Message());
         System.out.println(" Program Started...");
         System.out.println(" Wait for 5 seconds...");
         System.out.println(" Program Ended...");
      } catch(Exception e) {


Program Started...
Wait for 5 seconds...
Program Ended...