为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
Java入门第三季_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

Java入门第三季

陈码农
难度入门
时长 5小时 0分
  • exceptiom
    查看全部
  • 818
    查看全部
    0 采集 收起 来源:经验总结

    2017-08-18

  • 异常使用的总结
    查看全部
    0 采集 收起 来源:经验总结

    2017-08-18

  • 1-8 捕获到的异常可以在当前方法的catch块中处理,也可以抛出给调用者去处理。
    查看全部
    0 采集 收起 来源:练习题

    2017-08-18

  • 1-7 java 中的异常链: package throwException; public class ChaimTest { public static void main(String[] args) { // TODO Auto-generated method stub ChaimTest ct = new ChaimTest(); try { ct.test2(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } public void test() throws Exception { throw new DruckExecption("开车不喝酒!!"); } public void test2() throws Exception { try { test(); } catch (DruckExecption e) { // TODO Auto-generated catch block RuntimeException newexc = new RuntimeException(e); //e.printStackTrace(); //newexc.initCause(e); throw newexc; } } }
    查看全部
    0 采集 收起 来源:练习题

    2018-03-22

  • 1-5.4 自定义异常类要继承Exception类或者其子类。
    查看全部
    0 采集 收起 来源:练习题

    2017-08-18

  • 1-5 java 中的异常抛出 throw - 将产生的异常抛出(动作) throws - 声明将要抛出何种类型的异常(声明) public void 方法名(参数列表) throws 异常列表{ //调用会抛出异常的方法或者: throw new Exception(); }
    查看全部
    0 采集 收起 来源:练习题

    2017-08-18

  • 使用 StringBuilder 或 StringBuffer 就可以避免这个问题。至于 StringBuilder 和StringBuffer ,它们基本相似,不同之处,StringBuffer 是线程安全的,而 StringBuilder 则没有实现线程安全功能,所以性能略高。因此一般情况下,如果需要创建一个内容可变的字符串对象,应优先考虑使用 StringBuilder 类。
    查看全部
  • 1-5.2 自定义异常: package throwException; public class DruckExecption extends Exception{ public DruckExecption() { } public DruckExecption(String message) { super(message); } } package throwException; public class testThrow { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub testThrow tt = new testThrow(); tt.compute(); tt.compute2(); // 需要在main方法中手动加上throws Exception } public void divide(int one, int two) throws Exception{ if(two==0) { //throw new Exception("两数相处,除数不能为0!!!"); throw new DruckExecption("两数相处,除数不能为0!!!"); //使用自定义异常 } else { System.out.println("两数相除的结果是: "+ one/two); } } public void compute() { try { divide(5, 0); } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); } } public void compute2() throws Exception{ divide(5, 0); } }
    查看全部
    0 采集 收起 来源:练习题

    2018-03-22

  • 1-5.1 throw and throws public class testThrow { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub testThrow tt = new testThrow(); tt.compute(); tt.compute2(); // 需要在main方法中手动加上throws Exception } public void divide(int one, int two) throws Exception{ if(two==0) { throw new Exception("两数相处,除数不能为0!!!"); } else { System.out.println("两数相除的结果是: "+ one/two); } } public void compute() { try { divide(5, 0); } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); } } public void compute2() throws Exception{ divide(5, 0); } }
    查看全部
    0 采集 收起 来源:练习题

    2018-03-22

  • ==: 判断两个字符串在内存中首地址是否相同,即判断是否是同一个字符串对象 equals(): 比较存储在两个字符串对象中的内容是否一致
    查看全部
  • //定义一个字符串“学习 JAVA 编程” String str = "学习 JAVA 编程"; //
    查看全部
  • 1-3 finally: public int test() { int count = 10; int result = 100; try { while (count > -1 ) { count--; result = (result + 100) / count; } return result; // 这里的return没有意义。 } catch (Exception e) { e.printStackTrace(); System.out.println("循环抛出异常!"); return result= 8888; // 如果有返回值,建议在这里return }finally { //finally 在执行完catch后一定会被执行。 System.out.println("this is finally!!"); System.out.println("my value is " + result); //return 9999; } //System.out.println("try cat had finish!"); // 如果catch和finally 都没有return,那可以在这里return,如果有return就不会执行到这里. //return 11111; } }
    查看全部
    0 采集 收起 来源:练习题

    2018-03-22

  • String 对象创建后则不能被修改,是不可变的,所谓的修改其实是创建了新的对象,所指向的内存空间不同
    查看全部
  • 处理异常 try-catch 以及try-catch-finally try{ //会抛出异常的方法 }catch(Exception e){ //处理该异常的代码块 }...(n 个catch块)...{ }finally{ //最终将要执行的一些代码 } 多重catch语句块书写原则:先小后大,先子类后父类 finally{}中一般处理收尾工作,例如文件和数据库的关闭
    查看全部

举报

0/150
提交
取消
课程须知
此部分为 Java 课程的进阶内容,适合具有一定 Java 基础的伙伴们学习,如果您是新手,建议您移步 《Java入门第一季》 和 《Java入门第二季》,在理解并掌握面向对象相关知识后再回来进修。
老师告诉你能学到什么?
本课程将学习 Java 中的异常处理、集合框架、字符串、常用类等,逐步学习掌握 Java 高级技术。
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!