JAVA system.exit
来源:互联网 发布:淘宝详情页价格 编辑:程序博客网 时间:2024/06/06 01:38
很容易从Java.lang.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> 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) { <span style="white-space:pre"> </span>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)是回到最上层
在一个if-else判断中,如果我们程序是按照我们预想的执行,到最后我们需要停止程序,那么我们使用System.exit(0),而System.exit(1)一般放在catch块中,当捕获到异常,需要停止程序,我们使用System.exit(1)。这个status=1是用来表示这个程序是非正常退出。
阅读全文
0 0
- JAVA system.exit
- java中System.exit()方法
- java中System.exit()方法
- Java: System.exit() 与安全策略
- java中System.exit()方法
- java System.getProperty(“ ”) System.exit(int status)
- java System.exit(0)和System.exit(1)区别
- Java System.exit(0)和System.exit(1)区别
- java的System.exit(0)和System.exit(n)
- java的System.exit(0)和System.exit(1)区别。
- java 何时使用System.exit() 方法
- java中 System.exit(1);是什么意思
- java.lang.System.exit()方法详解
- java中System.exit(0);是什么意思?
- java.lang.System的 System.exit(int code)解析
- java中system.exit (0)与system.exit (1)以及return
- java中system.exit(0)和system.exit(1)有什么区别
- java中system.exit(0)和system.exit(1)有什么区别
- 背景色渐变总结
- Qt下载地址
- 写给编程初学者
- HTML5中Web Storage本地存储
- 机器学习八 异常值
- JAVA system.exit
- C语言模拟实现C++的继承多态
- 树莓派3b配置opencv2.4.10
- 插入排序及优化
- get和post的区别
- Android源码内核设计思想读书笔记
- 读书笔记18 《麦肯锡工作法》 大岛祥誉
- bzoj 2144: 跳跳棋
- Components of Ryu