Program to demonstrate how to terminate a program using System and Runtime class in Java
package com.hubberspot.example; public class JavaTerminate { public static void main(String[] args) { int i = 0; if (i > 0) { // 1. In order to terminate a Java Application // we can use System.exit(int) to exit a Java // Application. System.exit(i); } else { // 2. In order to terminate a Java Application // another way we can use is creating a Runtime Object // and calling exit(int) of Runtime to terminate the Java // Application. Runtime runtime = Runtime.getRuntime(); runtime.exit(i); } } }