![]() |
VOOZH | about |
In Java, the System.exit() method is present in the java.lang package. This method is used to explicitly terminate the currently running Java program. This method takes a status code. A non-zero value of the status code is generally used to indicate abnormal termination. When this method is invoked then we cannot perform any further tasks.
public static void exit(int status)
Example: Using the System.exit() method to exit the currently running program.
arr[0] = 1 arr[1] = 2 arr[2] = 3 arr[3] = 4 exit...
Explanation: In the above Java code, we use the exit() if the element is greater than 4 in the array, then we call the exit(0) with a status code as 0 and after that the program successfully exits.
Note: Use System.exit() carefully, specially in large applications, because it stops the JVM immediately.