Java System exit() Method
Example
Stop the program, so the code after System.exit() does not run:
public class Main {
public static void main(String[] args) {
System.out.println("Before exit");
System.exit(0);
System.out.println("After exit");
}
}
Definition and Usage
The exit() method stops the running program at once. The code after it does not run.
The status code tells the operating system how the program ended. Use 0 when everything went well, and another number, like 1, when something went wrong.
Syntax
public static void exit(int status)
Parameter Values
| Parameter | Description |
|---|---|
| status | Required. The status code. 0 means a normal end. Any other number means that the program ended because of an error. |
Technical Details
| Returns: | Nothing. The method never returns, because the program stops. |
|---|
Related Pages
❮ System Methods