1. References
Http://hi.baidu.com/accpzhangbo/blog/item/52aeffc683ee6ec238db4965.html
2. Parsing
Looking at the source code of Java.lang.System, we can find the description of the System.exit (status) method, as follows:
/** * 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&G t;. This method never returns normally. * <p> * The call <code>system.exit (n) </code> are effectively equivalent to * the call: * < Blockquote><pre> * Runtime.getruntime (). exit (N) * </pre></blockquote> * * @param Status exit status. * @throws SecurityException * If a security manager exists and its <code>checkExit</code> * Method doesn ' t allow to exit with the specified status. * @see java.lang.runtime#exit (int) */public static void exit (int status) {Runtime.getruntime (). Exit (STA TUS); }
It is clear from the comments that this method is used to end the currently running Java Virtual machine. How status is a non-0 parameter, then indicates an abnormal exit.
- System.exit (0) stops all the content in your entire virtual machine, and Dispose () just closes the window, but does not stop the entire application exit (). In any case, the memory is released! Which means that even the JVM is shut down, there's nothing in the memory.
- System.exit (0) is a normal exit program, while system.exit (1) or not 0 indicates an abnormal exit program .
- System.exit (status) exits the program regardless of the status value. There are different points compared to return: Return is back to the previous level, and System.exit (status) is back to the top
3. Example
In a if-else judgment, if our program is executed according to our expectations, and finally we need to stop the program, then we use System.exit (0), and System.exit (1) is generally placed in the catch block, when the exception is caught, the program needs to be stopped, We use System.exit (1). This status=1 is used to indicate that this program is not normally exited.
System.exit (0) and System.exit (1) differ