zoukankan      html  css  js  c++  java
  • 2016-2017-2 20155309南皓芯《java程序设计》第七周学习总结

    教材学习内容总结

    Lambda

    一种匿名方法
    表达式构成
    括号以及括号里用逗号分隔的参数列表
    仅有一个参数的可以省略括号
    ->符号
    花括号以及花括号里的语句
    仅有一条语句时可以省略花括号,并且这条语句的值将作为return返回值。
    作用域
    进行变量捕捉

    时间的度量

    格林威治标准时间(GMT),现已不作为标准时间使用,即使标注为GMT(格林威治时间),实际上谈到的的是UTC(Unix时间)时间。
    在1972年引入UTC之前,GMT与UT是相同的。
    秒的单位定义时基于TAI。也就是铯原子辐射的振动次数。
    世界协调时间(UTC),UTC考虑了地球自转越来越慢而有闰秒修正,确保UTC与UT相差不会超过0.9秒。

    年历简介

    儒略历修正了罗马历隔三年设置一闰年的错误,改采四年一闰。
    格里高利历将儒略历1582年10月4号星期四的隔天,订为格里高利历1582年10月15日星期五。
    ISO 8601标准采用统一的数据格式。

    时间轴上瞬间的Date

    Date有两个构造函数可以使用,一个可使用epoch毫秒数构建,另一个为无自变量构造函数,内部亦是使用System.currentTimeMillis()取得毫秒数,调用getTime()可取得内部保存的epoch毫秒数值。

    格式化时间日期的DateFormat

    DateFormat是个抽象类,其操作类是java.text.SimpleDateFormat,你可以直接构建SimpleDateFormat实例,或是使用DateFormat的getDateInstance()、getTimeInstance()、getDateTimeInstance等静态方法,用较简便方式按不同需求取得SimpleDateFormat实例。
    DateFormatDemo.java运行结果如下。

    SimpleDateFormat有一个parse()方法,可以按构建SimpleDateFormat时指定的格式,将指定的字符串剖析为Date实例。HowOld.java运行结果如下:

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

    1.格式化时间是什么意思?

    Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
    格式化是指对磁盘或磁盘中的分区进行初始化的一种操作,这种操作通常会导致现有的磁盘或分区中所有的文件被清除。格式化通常分为低级格式化与高级格式化。如果没有特殊指明的话,对硬盘的格式化通常是指高级格式化,而对软盘的格式化则通常同时包括这两者。
    2.不清楚ZonedDateTimeDemo.java程序运行结果中数字的含义。

    将ZonedDateTimeDemo.java程序改写如下

    import static java.lang.System.out;
    import java.time.*;
    
    public class ZonedDateTimeDemo2 {
    public static void main(String[] args) {
    LocalTime localTime = LocalTime.of(0, 0, 0);
    LocalDate localDate = LocalDate.of(2016, 4, 16);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(
         localDate, localTime, ZoneId.of("Asia/Shanghai"));
    
    out.println(zonedDateTime);
    out.println(zonedDateTime.toEpochSecond());
    out.println(zonedDateTime.toInstant().toEpochMilli());
    }
    }
    

    发现运行出来的数字与ZonedDateTimeDemo2.java的数字相差不多,于是可以判断出原来程序中的数字是机器时间起点至今经过的毫秒数。

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

    1.代码,取得时间信息为什么用了两个getTime()
    解决过程:第一个getTime()是Calendar实例方法,返回Date实例,第二个getTime()是Date实例方法,通过Date实例取得epoch毫秒数
    2.做了一个代码调试
    package chapter13;
    import java.util.Scanner;
    import java.util.Calendar;

    public class rili{
        public static void main(String args[])
        {
            int year,month,day;
            Scanner yasuo=new Scanner(System.in);
            System.out.print("输入年份:");
            year=yasuo.nextInt();
            System.out.print("输入月份:");
            month=yasuo.nextInt();
            System.out.print("输入日子:");
            day=yasuo.nextInt();
            Calendar rili=Calendar.getInstance();
            System.out.println("	");
            System.out.println("日	一	二	三	四	五	六");
            rili.set(year,month,day);//设置日期将日历翻到指定日期
            int xingqi=rili.get(Calendar.DAY_OF_WEEK)-1;//记录星期,如果是1就是周日,7代表周六,依次类推
            String a[]=new String[xingqi+31];//存放号码的数组字符串
            for(int i=0;i<xingqi;i++)
            {
                a[i]="**";
            }
            for(int i=xingqi,n=1;i<xingqi+31;i++)
            {
                if(n<=9)
                {   
                    a[i]=String.valueOf(n);             
                }
                else
                {
                    a[i]=String.valueOf(n);
                }   
                n++;
            }
            for(int i=0;i<a.length;i++)//输出数组部分
            {
                if(i%7==0)
                {
                    System.out.println("");//换行
                    System.out.printf("%s",a[i]);
                }
                else
                     System.out.printf("%s","	"+a[i]);
            }
        }
    }
    

    结果:

    代码托管https://git.oschina.net/bestiisjava2017/nhx20155309-Java

    上周考试错题总结

    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

    2.下面代码中共有()个线程?
    public class ThreadTest {
    public static void main(String args[]){
    MyThread myThread =new MyThread();
    Thread t1=new Thread(myThread);
    Thread t2=new Thread(myThread);
    t1.start();
    t2.start();
    }
    }
    class MyThread extends Thread {
    ...
    }
    答案是3个。

    3.以下()方法会使线程进入阻塞状态?
    A .
    Thread.sleep()
    B .
    wait()
    C .
    notify()
    D .
    interrupt()
    答案是ab

    4.iven 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

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

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

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

    结对及互评

    本周结对学习情况:
    20155220 吴思其
    结对学习情况:
    学习并指出错误
    上周点评情况:
    http://www.cnblogs.com/guyanlin/p/6657773.html#3662224

    http://www.cnblogs.com/gaoziyun11/p/6658661.html#3660705

    http://www.cnblogs.com/yangdi0420/p/6658701.html

    http://www.cnblogs.com/elevator/p/6659461.html

    学习与感悟

    在进行到这里,书上所学的内容已经进行的差不多了,并且上次云班课的考试让我意识到我在java的学习方面还有很多欠缺。以后会更加认真的学习与思考问题,不会的知识会立刻弄懂。

    学习进度条

    代码行数(新增/累积)	博客量(新增/累积)	学习时间(新增/累积)	
    

    目标 5000行 30篇 400小时
    第一周 50/100 1/1 24/24
    第二周 250/300 1/2 30/54
    第三周 552/852 1/3 16/60
    第四周 717/1569 1/4 10/70
    第五周 495/2064 1/5 6/76
    第六周 754/2818 1/6 7/82
    第七周 679/3493 2/8 5/87

    计划学习:7小时
    实际学习:5小时

  • 相关阅读:
    C++常用库
    如何学好VC和MFC(各前辈学*方法及感受整理)(五)
    如何学好VC和MFC(各前辈学习方法及感受整理)(一)
    基于Winsock API的VC网络编程实战
    const int *p和int * const p的区别(常量指针与指向常量的指针) .
    java中的“包”与C#中的“命名空间
    vc加载lib文件的方法
    C|C++中的静态全局变量,静态局部变量,全局变量,局部变量的区别
    如何学好VC和MFC(各前辈学习方法及感受整理)(三)
    如何学好VC和MFC(各前辈学习方法及感受整理)(二)
  • 原文地址:https://www.cnblogs.com/nhx19970709/p/6685569.html
Copyright © 2011-2022 走看看