20182304《数据结构与面向对象程序设计》第六周学习总结

学号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子句

代码调试中的问题和解决过程

  • 问题1:尝试运行老师给的测试代码,结果出现输出异常(最后的语句没有输出结果)

  • 问题1解决方案:问题的原因一方面是我将应用混合运行,将代码分开运行后就可以得出正常结果。另一方面是我并不理解代码功能。

  • 通过查阅JDK文档,我对文件操作有了基本的了解
    - 1 文件新建、删除等(查阅Fire类)


    配合代码,这样我们就可以大致明白每步操作的具体含义了
    - 2 使用FileOutputStream和FileInputStream类读写

 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文档查找对应的方法,对应语句的含义就很好理解了,其余的内容就不放上来了

代码托管

上周考试错题总结

  • 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.

结对及互评

评分标准

  1. 正确使用Markdown语法(加1分):

    • 不使用Markdown不加分
    • 有语法错误的不加分(链接打不开,表格不对,列表不正确...)
    • 排版混乱的不加分
  2. 模板中的要素齐全(加1分)

    • 缺少“教材学习中的问题和解决过程”的不加分
    • 缺少“代码调试中的问题和解决过程”的不加分
    • 代码托管不能打开的不加分
    • 缺少“结对及互评”的不能打开的不加分
    • 缺少“上周考试错题总结”的不能加分
    • 缺少“进度条”的不能加分
    • 缺少“参考资料”的不能加分
  3. 教材学习中的问题和解决过程, 一个问题加1分

  4. 代码调试中的问题和解决过程, 一个问题加1分

  5. 本周有效代码超过300分行的(加2分)

    • 一周提交次数少于20次的不加分
  6. 其他加分:

    • 周五前发博客的加1分
    • 感想,体会不假大空的加1分
    • 排版精美的加一分
    • 进度条中记录学习时间与改进情况的加1分
    • 有动手写新代码的加1分
    • 课后选择题有验证的加1分
    • 代码Commit Message规范的加1分
    • 错题学习深入的加1分
    • 点评认真,能指出博客和代码中的问题的加1分
    • 结对学习情况真实可信的加1分
  7. 扣分:

    • 有抄袭的扣至0分
    • 代码作弊的扣至0分
    • 迟交作业的扣至0分

点评模板:

  • 博客中值得学习的或问题:
    • 博客中解决的问题较少
    • 学习不够细致深入
    • 代码中值得学习的或问题:
    • 基于评分标准,我给本博客打分:14分。

点评过的同学博客和代码

  • 本周结对学习情况
    • 20182302
      • 结对学习内容
      • 共同讨论文件操作基础内容
      • 用不同方法实现多态
      • 设计程序进行异常捕获
      • 上周博客互评情况
    • 20182302

其他(感悟、思考等,可选)

  • 对目前所学习的知识没有一个很好的掌握理解,比较茫然

  • 自学能力有待于加强

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 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小时

  • 改进情况:目前学习效率仍然不高

(有空多看看现代软件工程 课件
软件工程师能力自我评价表
)

参考资料

posted @ 2019-10-15 23:35  20182304张子正  阅读(192)  评论(2编辑  收藏  举报