Shut down hook

void addShutdownHook(Thread hook)
Registers a new virtual-machine shutdown hook.
boolean removeShutdownHook(Thread hook)
De-registers a previously-registered virtual-machine shutdown hook.

public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();

    runtime.addShutdownHook(new Thread(){
      public void run(){
        System.out.println("Shut down");
        
      }
      
    });
  }
}

The output:


Shut down
Home 
  Java Book 
    Essential Classes  

Runtime:
  1. Runtime class
  2. Get the instance of a runtime
  3. Get the memory in your Java virtual machine
  4. Shut down hook
  5. Get the available processor
  6. Exit and halt Java virtual machine
  7. Run garbage collector and finalization methods
  8. Execuate a system command