System. exit, policystem. exit in Java
Exit the program in java and often use System. exit (1) or System. exit (0 ).
View the source code of the System. exit () method, as shown below:
1 /** 2 * Terminates the currently running Java Virtual Machine. The 3 * argument serves as a status code; by convention, a nonzero status 4 * code indicates abnormal termination. 5 * <p> 6 * This method calls the <code>exit</code> method in class 7 * <code>Runtime</code>. This method never returns normally. 8 * <p> 9 * The call <code>System.exit(n)</code> is effectively equivalent to10 * the call:11 * <blockquote><pre>12 * Runtime.getRuntime().exit(n)13 * </pre></blockquote>14 *15 * @param status exit status.16 * @throws SecurityException17 * if a security manager exists and its <code>checkExit</code>18 * method doesn't allow exit with the specified status.19 * @see java.lang.Runtime#exit(int)20 */21 public static void exit(int status) {22 Runtime.getRuntime().exit(status);23 }
When the status is 0, the program Exits normally. If the status is not 0, the program exits unexpectedly. Terminate the current Java VM.
The System. exit () method returns the top layer of the program. return returns the last layer compared to it.
After the program runs the System. exit () method, it stops running. If you want the program to exit the current use case only after it encounters System. exit and do not exit the current program, consider doing something wrong with the exception.
In java, Systemexit (0); what is it?
System is a Java class. Call the exit (0) method to terminate the VM, that is, exit your Java program. The parameters in the brackets are the return values of Process Termination.
For your reference, this is better than that.
Public static void exit (int status) terminates the currently running Java virtual machine. The parameter is used as the status code. By convention, a non-0 Status Code indicates that an exception is terminated.
This method calls the exit method in the Runtime class. This method will never return normally.
Calling System. exit (n) is actually equivalent to calling:
Runtime. getRuntime (). exit (n)
Parameters:
Status-exit status.
Throw:
SecurityException-if the security manager exists and its checkExit method cannot exit in the specified state.
In java, Systemexit (1); what is it?
The exit method is used to interrupt a running Java virtual machine. The integer parameters contained in the exit method are used to indicate the status code. By convention, a non-zero Status Code indicates that an exception is terminated. The zero Status Code indicates that the entire program is successfully terminated.