转:http://www.cnblogs.com/xwdreamer/archive/2011/01/07/2297045.html

1.参考文献

http://hi.baidu.com/accpzhangbo/blog/item/52aeffc683ee6ec238db4965.html

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是非零参数,那么表示是非正常退出。

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

3.示例

在一个if-else判断中,如果我们程序是按照我们预想的执行,到最后我们需要停止程序,那么我们使用System.exit(0),而 System.exit(1)一般放在catch块中,当捕获到异常,需要停止程序,我们使用System.exit(1)。这个status=1是用来 表示这个程序是非正常退出。

System.exit(0)和System.exit(1)区别(转)的更多相关文章

  1. System.exit(0)和System.exit(1)区别:

    System.exit(0)是将你的整个虚拟机里的内容都停掉了,而finish()只是退出了activity,并没有退出应用,Application还是存在于内存中的,除非被系统回收.无论如何,内存都 ...

  2. System.exit(0)和System.exit(1)区别

    System.exit(0)是将你的整个虚拟机里的内容都停掉了 ,而dispose()只是关闭这个窗口,但是并没有停止整个application exit() .无论如何,内存都释放了!也就是说连JV ...

  3. JAVA System.exit(0) 和 System.exit(1) 的区别

    System.exit(int state) 方法都是来结束当前运行的java虚拟机.所有System.exit(1).System.exit(0) 执行后都会退出程序. state为0时时正常退出, ...

  4. 对于System.exit(0)和System.exit(1)的一般理解

    public static void exit(int status) 终止当前正在运行的 Java 虚拟机.参数用作状态码:根据惯例,非 0 的状态码表示异常终止. 该方法调用 Runtime 类中 ...

  5. system.exit(0) vs system.exit(1)

    2.解析 查看java.lang.System的源代码,我们可以找到System.exit(status)这个方法的说明,代码如下: /** * Terminates the currently ru ...

  6. Environment.Exit(0) 、Application.Exit() 、this.Close() 、this.Dispose()的区别

    Application.Exit:通知winform消息循环退出.程序会等待所有的前台线程终止后才能真正退出.是一种强行退出方式,就像 Win32 的 PostQuitMessage().它意味着放弃 ...

  7. android中 System.exit(0)的理解

    public class HelloGoodbye{ try{ System.out.println(“Hello World”); System.exit(0); } finally { Syste ...

  8. System.exit(0)作用

    System.exit(0)作用   public class HelloGoodbye{ try{ System.out.println(“Hello World”); System.exit(0) ...

  9. exit(0)、exit(1)、exit(-1)的区别

    exit(0) - 正常退出 exit(1) - 异常退出(除0外,其他值均为异常退出)

随机推荐

  1. SQLmap注入

    一.安装 先安装Python2.7 下载SQLmap:http://sqlmap.org/ 下载文件解压到Python文件目录下 然后设置环境变量:D:\Python27\sqlmap 在cmd查看是 ...

  2. [CSP-S模拟测试]:小奇的仓库(warehouse)(树形DP)

    题目背景 小奇采的矿实在太多了,它准备在喵星系建个矿石仓库.令它无语的是,喵星系的货运飞船引擎还停留在上元时代! 题目描述 喵星系有$n$个星球,星球以及星球间的航线形成一棵树.从星球$a$到星球$b ...

  3. python 3.x上安裝web.py

    python 3.x上安裝web.py 查询之后,安装时使用pip3 install web.py==0.40.dev0 最終可以运行 app.py import weburls=(    '/',' ...

  4. Flask Session ,pymysql ,wtforms组件 虚拟virtualenv venv

    https://www.cnblogs.com/wupeiqi/articles/5713330.html session def create_app(): print() app=Flask(__ ...

  5. jmeter 线程组之间传递动态变化的变量值

    http://www.51testing.com/html/01/n-3725501.html https://www.jianshu.com/p/73832bae65af https://blog. ...

  6. 网关中加入熔断机制(Hystrix)

    网关中加入熔断机制 在网关中加入熔断机制 添加依赖项 spring-cloud-gateway项目POM文件加入spring-cloud-starter-netflix-hystrix <dep ...

  7. 记录一次kibana启动Unable to fetch data from reporting collector

    版本不匹配导致 应该es与kibana版本一致 本文链接:https://blog.csdn.net/qq_33293753/article/details/87894882

  8. Spring学习笔记(12)——aop

    先了解AOP的相关术语:1.通知(Advice):通知定义了切面是什么以及何时使用.描述了切面要完成的工作和何时需要执行这个工作.2.连接点(Joinpoint):程序能够应用通知的一个"时 ...

  9. jq表单提交加正则验证

    验证方法:姓名,手机,邮箱这些,鼠标点击移走用input的失去焦点blur事件.若为空,给input下方加提示消息. html: input框是引用bootstrap的css <div clas ...

  10. DOM查询的其他方法

    document.body 保存的是body的引用 documen.documentElement 保存的是html根标签 document.all 代表页面中所有的元素 getElementsByC ...