A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张钧杰 中级黑马   /  2012-5-26 20:54  /  1747 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

System.exit(0);
这里面的0是什么意思啊!

2 个回复

倒序浏览
查看java.lang.System的源代码,我们可以找到System.exit(status)这个方法的说明,代码如下:



/**
     * 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> is 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 exit with the specified status.
     * @see        java.lang.Runtime#exit(int)
     */
    public static void exit(int status) {
        Runtime.getRuntime().exit(status);
    }

注释中说的很清楚,这个方法是用来结束当前正在运行中的java虚拟机。如何status是非零参数,那么表示是非正常退出。

System.exit(0)是将你的整个虚拟机里的内容都停掉了 ,而dispose()只是关闭这个窗口,但是并没有停止整个application exit() 。无论如何,内存都释放了!也就是说连JVM都关闭了,内存里根本不可能还有什么东西
System.exit(0)是正常退出程序,而System.exit(1)或者说非0表示非正常退出程序
System.exit(status)不管status为何值都会退出程序。和return 相比有以下不同点:   return是回到上一层,而System.exit(status)是回到最上层

评分

参与人数 1技术分 +1 收起 理由
攻城狮 + 1 赞一个!

查看全部评分

回复 使用道具 举报
System.exit(0)中断虚拟机的运行,退出应用程序,0表示没有异常正常退出;
exit(1)表示非正常退出
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马