What is System.exit() in JAVA ?
In Java, System.exit() is a command used to immediately shut down the running program. Think of it like a "Kill Switch" or an emergency exit button for your code. Once this line is reached, the program stops everything it is doing and closes, even if there is more code left to run. How it Works When you call System.exit(n) , you must provide an integer (usually 0 or 1 ) inside the parentheses. This is called a Status Code : System.exit(0) : Tells the computer, "The program finished successfully with no problems. System.exit(1) (or any non-zero number): Tells the computer, "The program crashed or stopped because of an error. Layman's Example: The ATM Imagine you are writing code for an ATM machine. The user inserts a card. The user enters the wrong PIN three times. For security, you want the program to stop immediately so no one can try a fourth time. Example: if (failedAttempts == 5 ) { System.out...