System.exit() in Java Last Updated : 21 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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.This method takes a single argument, the status code. If it is 0, then it indicates that the termination is completed.If a non-zero status code is passed, then it shows the termination is unsuccessful for reasons like abnormal behaviour of the program or any exception.Syntax of System.exit() Methodpublic static void exit(int status)Parameter: It takes a single argument, the status, which is generally a zero or non-zero value.Return Type: This method does not return anything but exits the current program.Exception: This method might throw SecurityException if a security manager is present and the exit() operation is restricted.Example: Using the System.exit() method to exit the currently running program. Java // Java program to demonstrate working of System.exit() import java.util.*; import java.lang.*; public class Geeks { public static void main(String[] args) { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8}; for (int i = 0; i < arr.length; i++) { if (arr[i] > 4) { System.out.println("exit..."); // Terminate JVM System.exit(0); } else System.out.println("arr["+i+"] = " + arr[i]); } System.out.println("End of Program"); } } Outputarr[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. Comment More infoAdvertise with us Next Article Java if-else Statement A Amit Khandelwal 1 Improve Article Tags : Java Practice Tags : Java Similar Reads Java System.exit(0) vs C++ return 0 Java and C++ are languages with different applications and design goals. C++ is an extension of procedural programming language C and Java relies on a Java virtual machine to be secure and highly portable. This leads them to many differences. In this article, we will see the difference between C++ r 3 min read Java if-else Statement The if-else statement in Java is a powerful decision-making tool used to control the program's flow based on conditions. It executes one block of code if a condition is true and another block if the condition is false. In this article, we will learn Java if-else statement with examples.Example:Java/ 3 min read Java Continue Statement In Java, the continue statement is used inside the loops such as for, while, and do-while to skip the current iteration and move directly to the next iteration of the loop.Example:Java// Java Program to illustrate the use of continue statement public class Geeks { public static void main(String args 4 min read Jump Statements in Java Jumping statements are control statements that transfer execution control from one point to another point in the program. There are three Jump statements that are provided in the Java programming language: Break statement.Continue statement.Return StatementBreak statement1. Using Break Statement to 5 min read Java Break Statement The Break Statement in Java is a control flow statement used to terminate loops and switch cases. As soon as the break statement is encountered from within a loop, the loop iterations stop there, and control returns from the loop immediately to the first statement after the loop. Example:Java// Java 3 min read Break and Continue statement in Java The break and continue statements are the jump statements that are used to skip some statements inside the loop or terminate the loop immediately without checking the test expression. These statements can be used inside any loops such as for, while, do-while loop. Break: The break statement in java 5 min read Like