Java asks _03 Basic grammar (015) _system.exit (0) What's the use of

Source: Internet
Author: User

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:

    1. 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.

    2. System.exit (0) is a normal exit program, while System.exit (1) or status 0 indicates an abnormal exit procedure.

    3. The program exits regardless of the status value.

Java FAQ _03 Basic Syntax (015) _system.exit (0) What's the use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.