20145109 《Java程序设计》第五周学习总结
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 |
参考资料
20145109 《Java程序设计》第五周学习总结的更多相关文章
- 201521123025<java程序设计>第五周学习总结
1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 1.2 ...
- Java程序设计第五周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 **代码阅读:Child压缩包内源代码 Child.java源代 ...
- 20145109《Java程序设计》第二周学习总结
20145109 <Java程序设计>第二周学习总结 教材学习内容总结 Variable : naming rule : Camel case no default value e.g : ...
- 20145109《Java程序设计》第一周学习总结
20145109 <Java程序设计>第一周学习总结 教材学习内容总结 About JVM, JRE, JDK JVM包含于JRE中,用于运行Java程序.JDK用于开发Java程序,包含 ...
- 20145213《Java程序设计》第九周学习总结
20145213<Java程序设计>第九周学习总结 教材学习总结 "五一"假期过得太快,就像龙卷风.没有一点点防备,就与Java博客撞个满怀.在这个普天同庆的节日里,根 ...
- 21045308刘昊阳 《Java程序设计》第九周学习总结
21045308刘昊阳 <Java程序设计>第九周学习总结 教材学习内容总结 第16章 整合数据库 16.1 JDBC入门 16.1.1 JDBC简介 数据库本身是个独立运行的应用程序 撰 ...
- 20145236 《Java程序设计》第九周学习总结
20145236 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 整合数据库 JDBC简介 1.JDBC是java联机数据库的标准规范.它定义了一组标准类与接口,标准API ...
- 20155304田宜楠2006-2007-2 《Java程序设计》第一周学习总结
20155304田宜楠2006-2007-2 <Java程序设计>第一周学习总结 教材学习内容总结 - 浏览教材,根据自己的理解每章提出一个问题 第一章 除了书上提到的开发工具还有什么适合 ...
- 20155303 2016-2017-2 《Java程序设计》第二周学习总结
20155303 2016-2017-2 <Java程序设计>第二周学习总结 教材学习内容总结 『注意』 "//"为单行批注符: "/*"与&quo ...
- 20145237 《Java程序设计》第九周学习总结
20145237 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 整合数据库 JDBC入门 ·数据库本身是个独立运行的应用程序 ·撰写应用程序是利用通信协议对数据库进行指令 ...
随机推荐
- Android 7.1.1 锁屏界面启动流程
前几天遇到一个低概率复现锁屏界面不显示,仅仅显示状态栏的问题,跟了下锁屏界面启动显示的流程,在这分享下,也方便以后自己查看.前面简介了下Zygote启动流程, Zygote进程启动后会首先创建一个Sy ...
- Hadoop格式化HDFS报错java.net.UnknownHostException: centos64
异常描述 在对HDFS格式化,执行hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示: [shirdrn@localhost bin]$ hadoop na ...
- C语言数据类型大小
数据类型大小是由操作系统和编译器共同决定的,但必须满足: short和int至少为16bit:long至少为32bit: short不能超过int,int不能超过long. 在主流编译器中,32位机和 ...
- pandas 读取文件
import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('G:timeCompare.txt', sep=' ', ...
- vijos P1740 聪明的质检员
题目链接:传送门 题目大意:给你n个物品,每件物品有重量 W 和价值 V,给m个区间,和一个标准值.(n,m最大200000) 要求找到一个值x,使得m个所有区间的权值和与标准值的差的绝对值最小.单个 ...
- Codeforces 678E(Another Sith Tournament)
题目链接:传送门 题目大意:有n个人决斗(n<=18),每两个人之间都有一定几率杀死对方,一次进行一次决斗,胜利者成为擂主继续接受决斗直到只剩下一个人,你是一号,问你最大有多大几率存活到最后. ...
- js写css()方法,记得加引号“ ”,除非是数字
js写css()方法,记得加引号“ ”,除非是数字.如: $("#android").css({ "position": "absolute" ...
- POJ 2773 Happy 2006(容斥原理+二分)
Happy 2006 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10827 Accepted: 3764 Descr ...
- 通过手机浏览器打开APP或者跳转到下载页面.md
目录 通过手机浏览器打开APP或者跳转到下载页面 添加 schemes 网页设置 参考链接 通过手机浏览器打开APP或者跳转到下载页面 以下仅展示最简单的例子及关键代码 由于硬件条件有限,仅测试了 A ...
- Go & SQLite on Windows
一般golang使用的sqlite驱动包都是github.com/mattn/go-sqlite3,但是官方并没有直接支持windows平台的编译,因为windows平台编译默认需要gcc支持 其实解 ...