- 浏览: 197815 次
- 性别:
- 来自: 哈尔滨
文章分类
- 全部博客 (267)
- java.lang (8)
- 问题汇总 (21)
- 异常记录 (20)
- 功能实现 (19)
- 面试总结 (25)
- 技巧总结 (8)
- 常用代码 (4)
- 编程习惯 (3)
- 编码规则 (3)
- java.util (10)
- java.io (1)
- JavaWeb (9)
- MySQL (16)
- SVN (3)
- MyBatis (11)
- Velocity (7)
- 其他知识 (10)
- 人生哲理 (1)
- 人生故事 (1)
- 自我感悟 (1)
- shiro (3)
- 基础知识 (0)
- 问题总结 (1)
- Spring 标签 (1)
- Spring (3)
- 点滴生活 (1)
- DOS (1)
- CAS (4)
- Linux (9)
- Storm (6)
- Shell (1)
- regex (1)
- Collection (4)
- poi (1)
- 经典语句 (1)
- NIO (5)
- concurrent (14)
- RPC (1)
- zookeeper (3)
- 待整理 (2)
- Hadoop (9)
- RabbitMq (2)
- flume (1)
- hive (7)
- hbase (4)
- kafka (1)
- scala (1)
- GC (0)
- java.util.concurrent.atomic (1)
- java.lang.ref (6)
- JVM (2)
- algorithm (1)
- conception (1)
- java key word (1)
- sun.misc (1)
最新评论
问题:System.exit(0)与return的区别
1.try catch finally 若catch中有return ,finally中代码依然可以执行
参考文献:try catch 中添加 return ,fianlly中的代码是否依然会执行?
2.try catch finally 若catch中有System.exit(0),finally中代码不可以执行
Console输出:
catch
3.区别
多线程例子:
4.总结
(1)在main()中的区别:
当用return;返回时,main()并不能立即运行结束,而用System.exit(数值);时,main()将立即无条件的结束
(2)system.exit(0)表示程序正常退出,system.exit(1)表示非正常退出,都没有返回值。return则返回至调用该方法的地方,如果后面还有代码则继续执行
(3)return返回上一层调用;System.exit(n)返回最上一层调用
参考文献:
http://bbs.csdn.net/topics/280057476
http://blog.csdn.net/mmllkkjj/article/details/6149043
1.try catch finally 若catch中有return ,finally中代码依然可以执行
参考文献:try catch 中添加 return ,fianlly中的代码是否依然会执行?
2.try catch finally 若catch中有System.exit(0),finally中代码不可以执行
public static void main(String[] args) { try{ int result = 0/0 ; System.out.println(result); }catch(Exception e){ System.out.println("catch"); System.exit(0); }finally{ System.out.println("finally"); } System.out.println("after finally"); }
Console输出:
catch
3.区别
方法 | return | System.exit(n) |
main() | 不能立即终止JVM运行 | 立即终止JVM运行 |
被调用方法 | 返回方法调用位置,其后的方法可以正常运行 | 终止运行,其后方法不执行 |
多线程例子:
new myThread().start(); if(条件为真) return; //此处的return并不能立即结束main。等待线程myThread //若换成System.exit(数值);则立即无条件地结束。 //其它代码
4.总结
(1)在main()中的区别:
当用return;返回时,main()并不能立即运行结束,而用System.exit(数值);时,main()将立即无条件的结束
(2)system.exit(0)表示程序正常退出,system.exit(1)表示非正常退出,都没有返回值。return则返回至调用该方法的地方,如果后面还有代码则继续执行
(3)return返回上一层调用;System.exit(n)返回最上一层调用
参考文献:
http://bbs.csdn.net/topics/280057476
http://blog.csdn.net/mmllkkjj/article/details/6149043
发表评论
-
京东商城--商城研发部面试
2017-12-01 19:30 5472017年12月01日 笔试题目 1. final fina ... -
海量日志数据,提取出某日访问百度次数最多的那个IP
2017-11-29 21:18 2176问题:一个的日志文件中存放IP地址,按照访问量对IP地址取访问 ... -
输出十进制数字的二进制数的表示
2017-11-03 23:16 1048一、代码如下: public static void m ... -
将数组中的内容随机打乱
2017-10-27 22:45 464问题:斗地主游戏,开局会将纸牌重新打乱,请用数组的随机排序实现 ... -
JVM基础
2017-10-26 22:41 375一、Java 运行时区域 《 ... -
String为什么使用final 修饰
2017-10-25 22:32 907主要是为了”安全性“和”效率“的缘故 1、由于String类 ... -
沐金地面试记录
2017-10-25 22:15 45710.25 下午同事帮忙投递的,约在晚上面试,下班之后赶紧去了 ... -
JD广告部面试经历
2017-10-23 16:46 384同事的同事招聘,于是同事帮忙推荐了一下! 2017年10月1 ... -
编程题目(一)
2017-09-28 22:28 3611.函数:参数为两个字符串a,b ,判断 b 中是否包含 a ... -
值传递与引用传递
2017-05-30 12:25 289一、值传递与引用传递 其实按值还是按引用的区别在于“是否在传 ... -
装箱与拆箱
2016-10-24 22:46 464public class IntegerTest { ... -
可变性与不可变性
2015-06-01 20:55 405String StringBuilder StringBuff ... -
CS架构和BS架构的区别
2015-05-25 08:50 435一、简介 1.C/S结构,即 ... -
HTTP常见响应状态码
2015-05-20 08:26 378问题:程序调试过程中 ... -
JIT的概念
2015-05-19 18:48 653参考文献: http://blog.csdn.net/yan ... -
JDK与JRE与JVM的区别
2015-05-19 18:45 10481.JDK (1)概念 JDK : Java Developm ... -
运行时与编译时
2015-05-17 18:05 496运行时与编译时 博文转载:http://www.import ... -
重载(overloading)与重写(overriding)
2015-05-17 15:50 593问题:重载(overloading)与重写(overridin ... -
==和equals
2015-05-15 20:07 611参考文献: http://www.cnblogs.com/zh ... -
return finally 与 System.exit(n)
2015-05-10 18:00 596问题:System.exit(n);的含义以及作用 说明: ...
相关推荐
System.out.println("#ERROR# Invalid reader index '"+args[0]+"'. Last valid index is " + (terminals.size()-1) ); System.exit(3); // throw new Exception( "Invalid reader index '"+iReader+"'. Last ...
import java.util.*; class MyException extends Exception{ String message; MyException(int age){ message=age+"年龄异常";... System.exit(0); } System.out.println(a.getAge()); } }
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents txtMin As System.Windows.Forms.TextBox Friend WithEvents txtMax As System.Windows.Forms.TextBox Friend WithEvents ...
C#做的俄罗斯方块游戏using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Xml; using System.IO; using System.Security....
System.out.println("[7] Exit"); System.out.print("Enter choice [1-7]: "); choice = sc.next().charAt(0); System.out.println(); // process choice by calling helper methods switch(choice) { case ...
简单分析了linux下system函数的相关内容,具体内容如下 int __libc_system (const char *line) { ...exit 0) == 0; return do_system (line); } weak_alias (__libc_system,
System.exit(0); } } Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); isExit = ...
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick If (Me.Visible = False) Then Me.Show() ...
System.exit(0); } else // 注册 if (str.equals("注 册")) { System.out.println("注 册"); } // 注册 else if (str.equals("忘记密码")) { System.out.println("忘记密码"); } else { System.out....
str.getChars(0,str.length(),c,0); if(c[0]>='a'&&c[0]) { c[0]=(char)(c[0]-32); } for(int i=1;i<=c.length-1;i++) { if(c[i]==' ') { c[i+1]=(char)(c[i+1]-32); } } str=new ...
private System.Windows.Forms.Button cmdExit; private System.Windows.Forms.Button cmdSet;// = new byte[2048]; <br> private bool bTsFlag=false; public GprsServer() { <br> ...
} 有条件循环 private void button1_Click(object sender, System.EventArgs e) { int sum=0; int x=0; while ((sum) & (x)) { x++; sum+=x; } string s2=Convert.ToString(x); MessageBox.Show(s2); } 运行显示 14...
Java 2实用教程(第三版)实验指导与习题解答 清华大学出版社 (编著 耿祥义 张跃平) 实验模版代码 建议使用文档结构图 (选择Word菜单→视图→文档结构图) 上机实践1 初识Java 4 实验1 一个简单的应用程序 ...
//System.exit(1); }else{ mobile = args[0].trim(); pwd = args[1].trim(); } //System.out.println("mobile:" + mobile); //System.out.println("password:" + pwd); fetion = new Fetion...
//System.exit(1); }else{ mobile = args[0].trim(); pwd = args[1].trim(); } //System.out.println("mobile:" + mobile); //System.out.println("password:" + pwd); fetion = new Fetion...
System.out.println("ffmpeg Process exitValue: " + exitVal); return true; } catch (Exception e) { System.out.println("ffmpeg exec cmd Exception " + e.toString()); } return false; }
给初学者的简单例题! private System.ComponentModel.IContainer components;... return 1; else if ((p.X > PaddleRect.Left + PaddleRect.Width/4) && (p.X <= PaddleRect.Left + PaddleRect.Width/2)) ...
1. try的意思,就是试着...4. 如果在try或者catch之中,执行System.exit(0); 那么 finally不会被执行,此外的情况,不管是Error还是return,finally块都会执行到。 5. 建议不清楚的拷贝代码或者自己写一份执行了看看。
System.exit(1); }// end if } catch (InterruptedException ine) { ine.printStackTrace(); System.exit(1); } // end catch if(sourceImage == null) { sourceImage = bImage; ...
System.exit(1); } } private ClassLoader createClassLoader(String name, ClassLoader parent) throws Exception { //CatalinaProperties解析$CATALINA_HOME\conf\catalina.properties, //并将...