Java System.exit() Method
The System.exit()
method in Java is used to terminate the currently running Java program. It takes an argument of type int
, which represents the exit status.
Typically, passing 0
means the program terminated normally without any errors. Any non-zero value usually indicates an abnormal termination due to an error or unexpected condition.
Here is a simple example:
public class SysExitExample {
public static void main(String[] args) {
System.out.println("Before exit.");
method(true);
System.out.println("This line will not be executed.");
}
public static void method(boolean flag) {
if (flag) {
System.exit(0);
}
System.out.println("This line inside method will not be executed.");
}
}
Output of the program:
Before exit.

Please log in or register to have a possibility to add comment.