Terminating currently running JVM

  You can able to kill the JVM using Runtime.getRuntime().exit() method. Yes, the System.exit() method also used for terminating current JVM. The System.exit() method is equivalent to Runtime.getRuntime().exit() method. For better understanding try with following example.


public class KillJVM {
  public static void main(String args[]) {
    try{
System.out.println("Divide by zero: " + (1/0));
    }
    catch(Exception e) {
System.out.println("Error details: " + e.getMessage());
Runtime.getRuntime().exit(1);
    }
  }
}

Comments

Popular Posts