20155314 2016-2017-2 《Java程序设计》第6周学习总结

20155314 2016-2017-2 《Java程序设计》第6周学习总结

教材学习内容总结

  • 理解流与IO
  • 理解InputStream/OutPutStream的继承架构
  • 理解Reader/Writer继承架构
  • 会使用装饰类
  • 会使用多线程进行并发程序设计

教材学习中的问题和解决过程

课后习题

所谓“实践是检验认识真理性的唯一标准”,我在IntelliJ IDEA上把教材第三章课后练习题又敲了一遍,给出了自己的答案,并加上了一些自己的分析,通过逐题进行代码调试实践的方式来深入对java类与对象的理解。小白在此恳请大家积极指出错误的地方(>_<)

8.4.1 选择题

  1. C 分析:

     public class Exercise8411 {
         public static void main(String[] args) {
             try {
                 int number=Integer.parseInt(args[0]);
                 System.out.println(number++);
             }catch (NumberFormatException ex) {
                 System.out.println("必须输入数字");
             }
         }
     }
    

  2. C 分析:

     public class Exercise8412 {
         public static void main(String[] args) {
             Object[] objs={"Java","7"};
             Integer number=(Integer)objs[1];
             System.out.println(number);
         }
     }
    

  3. B 分析:

     public class Exercise8413 {
         public static void main(String[] args) {
             try {
                 int number=Integer.parseInt(args[0]);
                 System.out.println(number++);
             }catch (NumberFormatException ex) {
                 System.out.println("必须输入数字");
             }
         }
     }
    



  4. ACD 分析:

     public class Exercise8414 {
         public static String readFile(String name) throws Throwable{
             FileInputStream input=new FileInputStream(name);
             return input.toString();
         }
     }
    

  5. ACD 分析:

     public class Exercise8415 {
         public static String readFile(String name) {
             FileInputStream input=null;
             try {
                 input=new FileInputStream(name);
             }catch (FileNotFoundException ex) {
     
             }
             return input.toString();
         }
     }
    

  6. CD 分析:

     class Exercise8416 {
         void doService() throws IOException {
     
         }
     }
     
     class exercise8416 extends Exercise8416 {
         @Override
         void doService() throws FileNotFoundException {
     
         }
    

    }

  7. B

     public class Exercise8417 {
         public static void main(String[] args) {
             try {
                 int number=Integer.parseInt(args[0]);
                 System.out.println(number++);
             }catch (ArrayIndexOutOfBoundsException|NumberFormatException ex) {
                 System.out.println("必须输入数字");
             }
         }
     }
    

  8. A

     public class Exercise8418 {
         public static void main(String[] args) {
             try {
                 int number=Integer.parseInt(args[0]);
                 System.out.println(number++);
             }catch (RuntimeException|NumberFormatException ex) {
                 System.out.println("必须输入数字");
             }
         }
     }
    

  9. A 分析:

     public class Exercise8419 {
         public static String readFile(String name) {
             try(FileInputStream input=new FileInputStream(name)) {
     
             }
         }
     }
    

  10. A

    public class Exercise84110 {
        public static void main(String[] args) {
            try(ResourceSome84110 some=new ResourceSome84110();
            ResourceOther84110 other=new ResourceOther84110()) {
                some.doSome();
                other.doOther();
            }catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    
    class ResourceSome84110 implements AutoCloseable {
        void doSome() {
            out.println("做一些事");
        }
        @Override
        public void close() throws Exception {
            out.println("资源Some被关闭");
        }
    }
    
    class ResourceOther84110 implements AutoCloseable {
        void doOther() {
            out.println("做其他事");
        }
        @Override
        public void close() throws Exception {
            out.println("资源Other被关闭");
        }
    

    }

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

  • 关于Java中非法输入的若干探索

    以课本P228—229代码为例:



代码托管

(statistics.sh脚本的运行结果截图)


上周考试错题总结

本周第一次采用了在蓝墨云班课上考试的形式,虽然最后因为很多同学提交失败而仅当练手,不过说实在的这种新颖的考试形式也给我敲了警钟——在25分钟的时间里需要作答30道选择题,而且还有不少多选题,甚至大多都是程序分析题,一道一道敲到电脑上再去运行肯定是来不及的(>_<),更要命的是很多题不去跑程序的话我根本无从下手(>o<)所以还是老老实实学扎实才是万全之策啊~

  • 已知某用户stud1,其用户目录为/home/stud1。如果当前目录为/home,使用一下哪个命令后可以进入/home/stud1/test?

    • A .cd home
    • B .cd stud1/test
    • C .cd /stud1/test
    • D .cd test

    正确答案: B
    我的答案: D
    分析:cd 等价于cd ~,也就是cd /home/userXXX

  • Which of the following methods will not compile?

    • A .

        private void method1(String name) {
        	if (name.equals("star"))
        	throw new IllegalArgumentException(name);
        } 
      
    • B .

        private void method2(int age) {
        	if (age > 30)
        	throw Exception();
        } 
      
    • C .

        public double method5() throws Exception {
        	return 0.7;
        } 
      
    • D .

        protected double method4() throws Exception {
        	throw new Throwable();
        } 
      

      正确答案: B D

      分析:Methods that compile successfully might not be implemented correctly.
      This question only asks about the methods that will follow the syntax rules so that they
      compile successfully.
      Option (a) code compiles successfully. Because IllegalArgumentException is a
      runtime exception, method1() can throw it without declaring it to be thrown in its
      throws statement.
      Option (b) code won’t compile. method2() throws a checked exception, that is,
      Exception, without declaring it to be thrown in its throws statement.
      Although the code in option. A
      method can throw a StackOverflowError (an unchecked exception) without including it in the throws clause of its method declaration.
      Option (d) code won’t compile. If a method declares to throw a checked exception, its body can’t throw a more general exception in its body. method4() declares to
      throw Exception but throws Throwable, which is not allowed (Exception subclasses
      Throwable).
      Option (c) code will compile successfully. If a method declares to throw Exception,
      it might not actually throw it. This only applies to Exception (because RuntimeException subclasses it), runtime exceptions, and errors

  • What is the output of the following code?

      class EJava {
          void method() {
              try {
                  guru();
                  return;
              } finally {
                  System.out.println("finally 1");
              }
          }
          void guru() {
              System.out.println("guru");
              throw new StackOverflowError();
          }
          public static void main(String args[]) {
              EJava var = new EJava();
              var.method();
          }
      }
    
    • A .
      guru
      finally 1
    • B .
      guru
      finally 1
      Exception in thread "main" java.lang.StackOverflowError
    • C .
      guru
      Exception in thread "main" java.lang.StackOverflowError
    • D .
      guru
    • E .
      The code fails to compile.

    正确答案: B

    分析:No compilation errors exist with the code.
    The method guru throws StackOverflowError, which is not a checked exception.
    Even though your code shouldn’t throw an error, it is possible syntactically. Your code
    will compile successfully.
    The call to the method guru is immediately followed by the keyword return, which is
    supposed to end the execution of the method method. But the call to guru is placed
    within a try-catch block, with a finally block. Because guru doesn’t handle the error
    StackOverflowError itself, the control looks for the exception handler in the method
    method. This calling method doesn’t handle this error but defines a finally block. The
    control then executes the finally block. Because the code can’t find an appropriate
    handler to handle this error, it propagates to the JVM, which abruptly halts the code.

结对及互评

评分标准

  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分

点评模板:

  • 博客中值得学习的或问题:

    • xxx
    • xxx
    • ...
  • 代码中值得学习的或问题:

    • xxx
    • xxx
    • ...
  • 基于评分标准,我给本博客打分:XX分。得分情况如下:xxx

  • 参考示例

点评过的同学博客和代码

感悟

这周因为清明节放假调休上了六天课,特别是周六还补周一的课,又是满课的一天,烧脑的数据结构、密码学什么的真心累(>_<)(还记得数据结构课上张岩老师谜之微笑:正好咱们来好好讲讲)

生活充满节奏感?!!

其次这周二遭遇了史上第一次数据结构实验的洗礼(; ̄ェ ̄)

HP-2147483647(´-`)

也许是进入了瓶劲期了吧,感觉Java真的学不动了,难受(>_<)目前已经离老师布置的教学进程差了整整两章:(那又有什么办法呢只能老老实实按照自己的进度龟速向前爬呗~希望自己能在清明假期调整一下状态,争取迎头赶上吧……(。ì _ í。)

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 20篇 300小时
第一周 34/34 1/4 12/12
第二周 360/394 1/5 16/28
第三周 701/1018 1/6 19/ 47 代码量激增( ̀⌄ ́)
第四周 608/1375 1/7 18/55 ①蹭了一节张健毅老师的Java课;②自己将数据结构课上所学的排序算法除了基数排序之外全部用C语言实现了一遍(`_´)ゞ;③本次博客史无前例的长:)
第五周 1205/2580 1/8 9/64 蹭了一节张健毅老师的Java课
第六周 826/3339 1/9 8/72
  • 计划学习时间:12小时

  • 实际学习时间:8小时

参考资料

posted @ 2017-04-02 21:05  20155314刘子健  阅读(241)  评论(6编辑  收藏  举报
Live2D