学号20182304 2019-2020-1 《数据结构与面向对象程序设计》第六周学习总结
教材学习内容总结
- 多态引用能够在不一样时间指向不一样类型对象,即运行一致性的方法出现不一致的行为。
- 使用父类声明的引用变量能够指向子类的对象,接口也能够实现多态
- 使用try-catch来实现未捕获的异常的处理。可使得异常被捕获进而不致使程序出现错误退出。
- 使用try写入可能产生异常的语句,使用catch来编写在捕获异常后继续执行的代码(能够为空)。
- 自定义异常
- throw:抛出异常
- throws:用于方法名的后面,作一个声明,表示下面可能会有这个异常,可是具体仍是要用throw来抛出异常。
- 在自定义异常中throws和throw必须是成对出现的,除非是用try-catch语句解决
- 异常的传递 :从产生位置沿方法调用链向上传递
教材学习中的问题和解决过程
- 问题1:子类能够转换成父类吗?当子类对象强制转换成父类时,是否能调用父类的方法?
- 问题1解决方案:子类能够转换成父类,由于子类其实是一种特殊的父类。第二个不行,调用的依然是子类的方法
- 问题2:为何要自定义异常?
- 问题2解决方案:从Exception类或它的一个后继类派生一个新类,就能够定义新的异常。在java里面针对于可能出现的公共的程序问题,都会提供相应的异常信息,可是不少时候这些异常信息每每不够去使用的,有些异常Java是不会提供的,因此就必须定义一个属于本身的异常类
- 问题3:必检测异常与免检测异常有什么区别?
问题3解决方案:必检测异常必须由方法捕获,或者必须在可能抛出或传递异常方法的throws子句中。java中惟一的免检测异常是RuntimeException类的对象或该类的后代类对象,免检异常不须要throws子句html
代码调试中的问题和解决过程
问题1:尝试运行老师给的测试代码,结果出现输出异常(最后的语句没有输出结果)

java
- 问题1解决方案:问题的缘由一方面是我将应用混合运行,将代码分开运行后就能够得出正常结果。另外一方面是我并不理解代码功能。
经过查阅JDK文档,我对文件操做有了基本的了解
- 1 文件新建、删除等(查阅Fire类)


配合代码,这样咱们就能够大体明白每步操做的具体含义了
- 2 使用FileOutputStream和FileInputStream类读写git
OutputStream outputStream1 = new FileOutputStream(file);//输入,指向文件
byte[] hello = {'H', 'e', 'l', 'l', 'o', ',', 'W', 'o', 'r', 'l', 'd', '!', '!', '!', '!', '!'};
outputStream1.write(hello);//按字节写入
outputStream1.flush();//刷新,第一种写法



InputStream inputStream1 = new FileInputStream(file);//第一种读法,一个一个字节读取
while (inputStream1.available() > 0) {
System.out.print((char) inputStream1.read() + " ");//区别?
}
inputStream1.close();
System.out.println("\n成功按位读取。。");

- 3 字节缓冲流(使用BufferedOutputStream和BufferedInputStream类)
- 做用:缓冲区能够大大提升读写效率,程序就不用现使用数据现读写浪费时间了
OutputStream outputStream2 = new FileOutputStream(file);//按字符串写入
BufferedOutputStream bufferedOutputStream2 = new BufferedOutputStream(outputStream2);
String content2 = "AAAAABBBBCCCCCDDDDget and put?";
bufferedOutputStream2.write(content2.getBytes(), 0, content2.getBytes().length);//依旧一位一位写入
bufferedOutputStream2.flush();
bufferedOutputStream2.close();


byte[] buffer = new byte[1024];
String content = "";//能够写东西,输出的时候会在前面
int flag = 0;
InputStream inputStream2 = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream2);
while ((flag = bufferedInputStream.read(buffer)) != -1) //-1时到达末尾,一次读取整个字符串


- 根据JDK文档查找对应的方法,对应语句的含义就很好理解了,其他的内容就不放上来了
(
数据结构
)ide
上周考试错题总结
- Abstract methods are used when defining
- A .interface classes
- D .arrays
- E .classes that have no methods
- An interface is a class that has defined some of its components, but leaves other components (methods) for you to implement. So, these components (methods) are referred to as abstract and defined in the interface class as abstract.
- 理解:是要重写父类中的全部抽象方法,即接口让咱们实现方法,而非没有方法
- Which of the following is true regarding Java classes?
- A .All classes must have 1 parent but may have any number of children (derived or extended) classes
- E .All classes can have either 0 or 1 parent class and any number of children (derived or extended) classes
- Further, since all Java classes inherit either directly or indirectly from the Object class, all Java classes have exactly 1 parent class.
- 理解:java类与Object类有直接看法的关系,因此每一个类都有一个父类,那Object类本身呢?Object是全部类的父类,也包括它本身
- A variable declared to be of one class can later reference an extended class of that class. This variable is known as
- D .polymorphic
- The term polymorphic means that the variable can have many forms. Under ordinary circumstances, Java is strongly defined that is, a variable, once declared to be of a type, can never change to be of a different type. The exception to this is that polymorphic variables can be any type of derived class (although not at the same time, the variable can change from one type to another).
- 理解:引用变量在不一样时刻指向不一样类型对象的能力即为多态
- In order to determine the type that a polymorphic variable refers to, the decision is made
- by the Java run-time environment at run time
- The polymorphic variable can take on many different types, but it is not know which type it has taken on until the program is executing. At the time the variable is referenced, then the decision must be made. That decision is made by the run-time environment based on the latest assignment of the variable.
- 理解:多态在程序运行中发挥做用
- Using the reserved word, super, one can
- A .access a parent class'constructor(s)
- B . access a parent class'methods and instance data
- E .none of the above
- The super reserved word provides a mechanism for accessing a parent class'methods and instance data (whether or not they are hidden). In addition, a parent class'constructor(s) may be accessed using super. So the correct answer is the combination of A and B which isn't an option so the correct answer is E.
- 理解:其实二者均可以,也能够调用父类的抽象方法构造方法与实例数据
- Interface classes cannot be extended but classes that implement interfaces can be extended.
- B .false
- Any class can be extended whether it is an interface, implements an interface, or neither. The only exception to this is if the class is explicitly modified with the word "final" in which case it cannot be extended.
- 理解:接口也能够被扩展,只有前面带final的不行。
- If class AParentClass has a protected instance data x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but can not redefine x to be a different type.
- B .false
- A derived class can redefine any of the instance data or methods of the parent class. The parent class'version is now hidden, but can be accessed through the use of super, as in super.x.
- 理解:能够用super更改x的数据类型
- You may use the super reserved word to access a parent class'private members.
- 理解:Super will allow access to all non-private members of a parent class but, not to the private ones.
结对及互评
评分标准
- 正确使用Markdown语法(加1分):
- 不使用Markdown不加分
- 有语法错误的不加分(连接打不开,表格不对,列表不正确...)
- 排版混乱的不加分
- 模板中的要素齐全(加1分)
- 缺乏“教材学习中的问题和解决过程”的不加分
- 缺乏“代码调试中的问题和解决过程”的不加分
- 代码托管不能打开的不加分
- 缺乏“结对及互评”的不能打开的不加分
- 缺乏“上周考试错题总结”的不能加分
- 缺乏“进度条”的不能加分
- 缺乏“参考资料”的不能加分
教材学习中的问题和解决过程, 一个问题加1分学习
代码调试中的问题和解决过程, 一个问题加1分测试
- 本周有效代码超过300分行的(加2分)
- 其余加分:
- 周五前发博客的加1分
- 感想,体会不假大空的加1分
- 排版精美的加一分
- 进度条中记录学习时间与改进状况的加1分
- 有动手写新代码的加1分
- 课后选择题有验证的加1分
- 代码Commit Message规范的加1分
- 错题学习深刻的加1分
- 点评认真,能指出博客和代码中的问题的加1分
- 结对学习状况真实可信的加1分
- 扣分:
- 有抄袭的扣至0分
- 代码做弊的扣至0分
- 迟交做业的扣至0分
点评模板:
- 博客中值得学习的或问题:
- 博客中解决的问题较少
- 学习不够细致深刻
- 代码中值得学习的或问题:
- 无
基于评分标准,我给本博客打分:14分。this
点评过的同窗博客和代码
- 本周结对学习状况
其余(感悟、思考等,可选)
目标 |
5000行 |
30篇 |
400小时 |
|
第五周 |
1600/2900 |
2/11 |
20/110 |
|
第六周 |
981 /3881 |
2/12 |
25/135 |
|
第三周 |
500/1000 |
3/7 |
22/60 |
|
第四周 |
300/1300 |
2/9 |
30/90 |
|
尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进本身的计划能力。这个工做学习中很重要,也颇有用。
耗时估计的公式:Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。
参考:软件工程软件的估计为何这么难,软件工程 估计方法
计划学习时间:30小时
实际学习时间:25小时
改进状况:目前学习效率仍然不高
(有空多看看现代软件工程 课件
软件工程师能力自我评价表)
参考资料