Click to enter _ more _java thousand ask
1, system.exit (0) What is the use of
Looking at the source code of Java.lang.System, we can find the System.exit (status) method, the source code is as follows:
Public Final class System {/** * Terminates the currently running Java Virtual machine. The * argument serves as a status code; By convention, a nonzero status * code indicates abnormal termination. * <p> * This method calls the <code>exit</code> method in class * <code>Runtime</code> . This method never returns normally. * <p> * The call <code>system.exit (n) </code> are effectively equivalent to * the call: * <blo Ckquote><pre> * Runtime.getruntime (). exit (N) * </pre></blockquote> * * @param status exit status. * @throws SecurityException * If a security manager exists and its <cod E>checkexit</code> * Method doesn ' t allow to exit with the specified status. * @see java.lang.runtime#exit (int) */ Public Static void Exit(intStatus) {Runtime.getruntime (). exit (status); }}
It is clear from the comments that this method is used to end the currently running Java Virtual machine. Parameter status as the status code, according to the Convention, a non-0 status code represents an exception, so the status if nonzero, then the indication is an abnormal exit. Calling System.exit (n) is actually equivalent to calling:
Runtime.getRuntime().exit(n);
For System.exit (0), the following points need to be noted:
System.exit (0) stops the entire virtual machine, which means that even the memory is freed. and Dispose () just closes the window, but does not stop the entire application.
System.exit (0) is a normal exit program, while System.exit (1) or status 0 indicates an abnormal exit procedure.
The program exits regardless of the status value.
Java FAQ _03 Basic Syntax (015) _system.exit (0) What's the use