• 20155232 2016-2017-3 《Java程序设计》第7周学习总结


    20155232 2016-2017-3 《Java程序设计》第7周学习总结

    教材学习内容总结

    • 第十三章

    1.Greenwich MeanTime,格林威治时间,简称GMT时间,由观察太阳而得来。

    2.Universal Time,世界时,UT。

    3.International Atomic Time,国际原子时,TAI。

    4.Coordinated Universal
    Time,世界协调时间,UTC。

    5.Unix时间,以1970年1月1日00:00:00为起点。

    6.epoch:java.util.Date epoch毫秒数。

    7.Julian Calendar(儒略历)四年一闰。

    8.Gergorian Calendar(格里高利历)。

    9.ISO 8601标准。

    10.如果想取得系统时间,方法之一是使用System.currentTimeMillis()方法,返回的是long类型整数,代表1970年1月1日0时0分0秒0毫秒至今经过的毫秒数,以此方法取到的是机器的时间观点,代表时间轴上的某一瞬间。

    11.Calendar是个抽象类,java.util.GregorianCalendar是其子类。通过Calendar的getInstance()取得的Calendar实例,默认就是取得GregorianCalendar实例。

    12.设定TimeZoneTimeZone的getdefault可以取得默认时区的信息。

    13.取得月份要通过getValue()方法,而不是使用oridinal()(从0开始)方法。

    14.ofPattern是java.time.format.DateFormatter的静态方法。

    15.对于年、月、星期、日的日期的差,则使用Preriod类定义。

    16.年历系统设计:java.time.chrono操作了java.time.chrono.Chronlogy接口的类。

    17.plus()另一方法接受java.time.temporal.temporalUnit实例,java.time.temporal.ChronoUnit是TemporalUnit实作类,使用enum实作。

    18.ofDays()、ofMonths()、ofWeeks()其实是Preriod的静态方法。

    19.JDK8新时间日期处理API中最重要的,就是清楚地将机器对时间的概念与人类对时间的概念区隔开来,让机器与人类对时间的概念的界限变得明显。

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

    因为学习本章有关时间与日期的,和之前的java语法内容比较起来相对简单,问题很少,页没有什么不太懂的地方。

    • 问题一

    在JAVA中如何计算一个程序的运行时间?那么在c语言中呢?

    • 解决方案
      java中:
      如下代码,运行前时间和运行后作差即可。
    long startTime = System.currentTimeMillis();//获取当前时间
    //doSomeThing();   //要运行的java程序
    long endTime = System.currentTimeMillis();
    System.out.println("程序运行时间:"+(endTime-startTime)+"ms");
    

    还有一种在网上看到的:是以纳秒为单位计算的。

    long startTime=System.nanoTime();   //获取开始时间  
    
    doSomeThing(); //测试的代码段  
    
    long endTime=System.nanoTime(); //获取结束时间  
    
    System.out.println("程序运行时间: "+(endTime-startTime)+"ns"); 
    
    
    

    C语言中:

    上网查询得到:C/C++中的计时函数是clock(),而与其相关的数据类型是clock_t。

    详细内容参考链接:
    C语言如何计算程序运行时间

    • 问题二

    课本p435 CalendarUtil.java代码中为什么要调用clone()?

    • 解决方案:

    如果要在Calendar实例上进行add()之类的操作,这个操作会修改Calendar本身,为了避免Calendar自变量被修改,所以俩个方法中都对第一个自变量进行了clone()复制。

    • 问题三

    Period与Duration有些难区别,那么如何区分呢?

    • 解决方案

    上网查询后,period是日期差,between()方法只接受LocalDate,不表示比“日”更小的单位,然而Duration是时间差,between()可以接受Temporal操作对象,也就是可以用LocalDate,LocalTime,LocalDateTime来计算Duration,不表示比“天”更大的单位。

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

    • 问题一:

    课本p432 HowOld.java中,代码如下:

    package cc.openhome;
    
    import java.util.*;
    import java.text.*;
    
    public class HowOld {
        public static void main(String[] args) throws Exception {
            System.out.print("输入出生年月日(yyyy-mm-dd):");
            DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
            Date birthDate = dateFormat.parse(new Scanner(System.in).nextLine());
            Date currentDate = new Date();
            long life = currentDate.getTime() - birthDate.getTime();
            System.out.println("你今年的岁数为:" + 
                      (life / (365 * 24 * 60 * 60 * 1000L)));
        }
    }
    
    

    运行结果输入1996-10-29后,今年岁数为21。

    • 解决方案

    因为这个范例单纯的使用了数字间的相加减计算出来的,是个简单示范,不够严谨,算出来的岁数也是错误的,因为还没有过10.29所以应该是20岁。应当在程序代码中加入判断是否过了月份,是否应该进行岁数的减一。

    • 问题二
      课本p442页HowOld2中:
      image
      这个运行结果正确,但是输入如下时,出现错误:
      image

    • 解决方案
      上网查询:
      image
      就是要长度保持一致,才不会出现错误。

    修改后运行成功:image

    代码托管

    • 代码提交过程截图:
      image
      image

    结对及互评

    评分标准(满分10分)

    1. 从0分加到10分为止

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

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

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

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

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

      • 一周提交次数少于20次的不加分

    6 其他加分:

    • 周五前发博客的加1分
      • 感想,体会不假大空的加1分
      • 排版精美的加一分
      • 进度条中记录学习时间与改进情况的加1分
      • 有动手写新代码的加1分
      • 课后选择题有验证的加1分
      • 代码Commit Message规范的加1分
      • 错题学习深入的加1分
        7 扣分:
      • 有抄袭的扣至0分
      • 代码作弊的扣至0分

    点评模板:

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

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

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

    • 参考示例

    点评过的同学博客和代码

    • 本周结对学习情况
      • 20155215

      • 结对学习内容

        • 一起讨论课本代码,共同解决代码编译报错问题。
        • 讨论分析上周考试留下来的部分没有解决的试题。
        • 讨论知识点,交换学习体会和总结学习难点。
    • 上周博客互评情况
      20155312
      20155225
      20145226
      20145207
      20155335

    上周考试错题总结

    • 1.下面哪条命令可以把 f1.txt 复制为 f2.txt ?

    A .cp f1.txt f2.txt

    B .copy f1.txt f2.txt

    C .cat f1.txt > f2.tx

    D .cp f1.txt | f2.tx

    E .copy f1.txt | f2.tx

    正确答案: A C

    • 错误分析

    我选择的是c,少选择了一个。此题是多选题。copy是Windows下的命令。cat f1.txt >f2.tx 通过输出重定向实现了复制。

    • 2.如果有以下代码段:
      Thread thread = new Thread(new ________________() {
      public void run() {...}
      });

    空白部分指定哪些类型可以通过编译?

    A .Runnable

    B .Thread

    C .Future

    D .Executor

    正确答案:AB

    • 错误分析:
      少选了A,查API文档,Thread 也实现了 Runnable 接口 。

    • 3.调用线程的interrupt()方法 ,会抛出()异常对象?

    A .IOException

    B .IllegalStateException

    C .RuntimeException

    D .InterruptedException

    E .SecurityException

    正确答案: D E

    • 错误分析:又是少选了一个选项。

    • 现有:

        3. import java.util.*;
        4.    class ForInTest  {
        5.static List list=new ArrayList();
        6.
        7.public static void main (String  []  args)  {
        8.list. add("a"); list. add("b");list. add( "c");
        9.    //insert code here
        10.    System.out.print (o);
        11.    }
        12.  }
    

    哪一行插入到第9行将导致输出“abc"?

    A .for (Iterator o : list.iterator(); o.hasNext (); )

    B .for (Iterator o : list)

    C .for (Object o : list.iterator())

    D .for (Object o : list)

    正确答案: D

    • 现有
    1. class Calc {
     2.  public static void main(String [] args) {
     3.    try {
     4.         int x = Integer.parselnt ("42a") ;
     5.     //insert code here
     6.         System.out.print ("oops");
     7.    }
     8.   }
     9. }
    

    下面哪行分别插入到第五行,会导致输 "oops" ?
    A .catch (IllegalArgumentException e) {

    B .} catch (IllegalStateException c) {

    C .} catch (NumbelFormatException n) {

    D .} catch (ClassCastException c) {

    正确答案:AC

    • 错误分析:少选择了C选项。
    • Given an instance of a Stream, s, and a Collection, c, which are valid ways of creating a parallel stream? (Choose all that apply.)
      给定一个Stream的实例s, 一个Collection的实例c, 下面哪些选项可以创建一个并行流?

    A .new ParallelStream(s)

    B .c.parallel()

    C .s.parallelStream()

    D .c.parallelStream()

    E .new ParallelStream(c)

    F .s.parallel()

    正确答案:DF

    • 错误分析:我选择了CE,There is no such class as ParallelStream, so A and E are incorrect.

    • Which of the following statements about the Callable call() and Runnable run() methods are correct? (Choose all that apply.)
      A .Both can throw unchecked exceptions.

    B .Callable takes a generic method argument.

    C .Callable can throw a checked exception.

    D .Both can be implemented with lambda expressions.

    E .Runnable returns a generic type.

    F .Callable returns a generic type.

    G .Both methods return void
    正确答案:ACDF

    • 错误分析:我选择的是D,这个都是书中的概念,换成英文后,有点读不太懂。
    • What are some reasons to use a character stream, such as Reader/Writer, over a byte stream, such as InputStream/OutputStream? (Choose all that apply.)

    A .More convenient code syntax when working with String data

    B .improved performance

    C .Automatic character encoding

    D .Built-in serialization and deserialization

    E .Character streams are high-level streams

    F .Multi-threading support
    正确答案:AC

    • Assuming zoo-data.txt is a multiline text file, what is true of the following method?
      private void echo() throws IOException {
      try (FileReader fileReader = new FileReader("zoo-data.txt");
      BufferedReader bufferedReader = new BufferedReader(fileReader)) {
      System.out.println(bufferedReader.readLine());
      }
      }

    A .It prints the first line of the file to the console.

    B .It prints the entire contents of the file.

    C .The code does not compile because the reader is not closed.

    D .The code does compile, but the reader is not closed.

    E .The code does not compile for another reason.

    正确答案:A

    • 错误分析
      This code compiles and runs without issue, so C and E are incorrect。这句话说代码运行无错误,所以CE都错了。

    • Assuming / is the root directory, which of the following are true statements? (Choose all that apply.)

    A ./home/parrot is an absolute path.

    B ./home/parrot is a directory.

    C ./home/parrot is a relative path.

    D .The path pointed to from a File object must exist.

    E .The parent of the path pointed to by a File object must exist.

    正确答案:A

    • 错误分析:Paths that begin with the root directory are absolute paths,开头是ROOT的就是absoute路径。
    • Suppose that the file c:ookjava exists. Which of the following lines of code creates an object that represents the file? (Choose all that apply.)

    A .new File("c:ookjava");

    B .new File("c:ookjava");

    C .new File("c:/book/java");

    D .new File("c://book//java");

    E .None of the above

    正确答案:BC

    • 错误分析:java虚拟机中的命令还是没有掌握熟练。

    感悟心得

    • 对教材感悟

    在第十三章中认识了Date与Calendar,使用了JDK8新的时间日期API,区分了机器与人类时间概念。

    • 对考试感悟

    在这次考试中,遇到了英文的题目,看到有点蒙,很多专用的英语单词不认识,导致题目出错。还有大部分题目因为是多选,怕出错就总是选择一个选项,没选够,分数也没有拿到。但是主要还是对课本的内容没有掌握熟练,因为每周两章内容,可能有点多,东西就会遗忘,有点杂乱。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 5000行 30篇 400小时
    第一周 15/15 1/1 23/26
    第二周 208/240 2/2 35/38
    第三周 376/584 3/3 32/38
    第四周 823/1407 4/4 28/30
    第五周 986/2393 5/5 21/26
    第六周 1258/3651 6/6 26/25
    第七周 575/4226 7/7 14/16

    尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进自己的计划能力。这个工作学习中很重要,也很有用。
    耗时估计的公式
    :Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。

    参考:软件工程软件的估计为什么这么难软件工程 估计方法

    参考资料

  • 相关阅读:
    LeetCode91 Decode Ways
    LeetCode93 Restore IP Addresses
    LeetCode92 Reverse Linked List II
    LeetCode90 Subsets II
    LeetCode89 Gray Code
    最长公共子序列及其引申问题
    constexpr:编译期与运行期之间的神秘关键字
    I/O模型: 阻塞、非阻塞、I/O复用、同步、异步
    LeetCode86 Partition List
    maven 安装 过程
  • 原文地址:https://www.cnblogs.com/lsqsjsj/p/6685876.html
Copyright © 2020-2023  润新知