20145109 《Java程序设计》第五周学习总结
2016-04-03 22:13
405 查看
20145109 《Java程序设计》第五周学习总结
教材学习内容总结
Chapter 8 Exception Handling
try, catch
All Exceptions are packed. If willing, 'try' to 'catch' instances, which are representative of exceptions, and deal with them.try { ... } catch (Exception ex) { ... }
Exception Inheritance Architecture
Exception are packed as throwable. Throwable includes Error and Exception. Error and its sub class represents serious system error and no dealing. As to mistakes in program design, Exception or its sub class are recommended. It's also called Exception Handling.Generally speaking, if some method can throw Throwable or subclass-instance, you must use 'try', 'catch' to handle it, except from Error and RuntimeException.
Multi-catch
try { ... } catch (IOException | InterruptedException | ClassCastException e) { e.printStackTrace(); }
catch? throws ?
If exception happens without sufficient info to deal with it when programming, we can throw exception. Thus, it is the cilent that handle it.public class FileUtil { public static String readFile(String name) throws FileNotFoundException { ... } }
Actually, when exception happens, we can handle what we can handle with 'try' 'catch', the left part we 'throw' to the client.
public class FileUtil { public static String readFile(String name) throws FileNotFoundException { StringBuilder text = new StringBuilder(); try { Scanner console = new Scanner(new FileInputStream(name)); while (console.hasNext()) { text.append(console.nextLine()).append('\n'); } } catch (FileNotFoundException ex) { ex.printStackTrace(); throw ex; } return text.toString(); } }
** Inheritance ** :
if the parent class declare some exception, the sub class overrides this method properly in these ways:
no declaration of throwing any exception by keyword 'throws'
throws some exceptions in the parent-class method
throws sub exceptions in the parent-class method
But the following is forbidden:
throws other exceptions with no declaration in the parent class
throws parent exceptions in the parent-class method
Stack Trace
The easiest way, is printStackTrace() .The stack trace infomation in the console will show the type of exception. The origin is on the top.
assert
In some running time or situation, a state must be or not be. It is called assertion.finally
No matter whether exception happens in 'try', if there's 'finally' block, it will be certain to execute.try { ... } finally { ... }
Try-With-Resources
try(Scanner console = new Scanner(new FileInputStream(name))) { ... }
Interface java.lang.AutoCloseable
Chapter 9 Collection & Map
java.util.List:
record the order of every instance and get them.java.util.Set:
no repeat of the instances.java.util.Queue:
yes, it's queue.教材学习中的问题和解决过程
代码调试中的问题和解决过程
其他(感悟、思考等,可选)
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 50/50 | 2/2 | 8/8 | |
第二周 | 100/150 | 2/4 | 8/16 | |
第三周 | 250/400 | 2/6 | 10/26 | 用git上传代码 |
第四周 | 300/700 | 2/8 | 12/38 | 用wc查看代码行数 |
第五周 | 100/800 | 1/9 | 10/48 |
参考资料
Java学习笔记(第8版)《Java学习笔记(第8版)》学习指导
...
相关文章推荐
- java多线程调用 单例类中一个的方法
- 20145201 《Java程序设计》第五周学习总结
- 20145227 《Java程序设计》第5周学习总结
- 20145235 《Java程序设计》第5周学习总结
- Java的Integer缓存
- JavaEE中向数据库写入数据乱码的问题
- 20145211《Java程序设计》第5周学习总结——独上高楼,望尽天涯路
- Java使用线程池递归压缩文件夹下面的所有子文件
- java泛型
- Spring.Net学习笔记(7)-事务
- 关于Spring MVC分页
- Java开发环境搭建与Intellij的安装和初始配置
- 通过Java字节码发现有趣的内幕之String篇(上)(转)
- jdk 1.7中HashMap的HashIterator实现细节小记
- Java命令学习系列(7):Javap(转)
- JAVA注解
- Java数据库篇
- 【JAVA】腾讯研发类在线笔试题之蛇形矩阵实现
- MYBATIS+SPRING 配置
- 排序算法之希尔排序(Java)