• 20145225《Java程序设计》 第5周学习总结


    20145225《Java程序设计》

    第5周学习总结

    教材学习内容总结

    第八章 异常处理

    8.1语法与继承架构

    1. try、catch:try、catch代表错误的对象后做一些处理。

    2. 异常继承架构:错误会被包装为对象,这些对象均可抛出,因此设计错误对象都继承自java.lang.Throwable类,Throwable定义了取得错误信息、堆栈追踪(Stack Trace)等方法,它有两个子类:java.lang.Error与java.lang.Exception。在此简述一下Error类与Exception类的区别,在Java中对于比较严重的问题,是通过Error类来进行描述的,而对于非严重的问题,则是通过Exception类来进行描述的。对于Error,一般不编写针对性的代码对其进行处理,因为此时已经超出了JVM的运行能力范围之外了。

    import java.util.Scanner;
    public class Average {
    public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    double sum = 0;
    int count = 0;
    while (true) {
    int number = console.nextInt();
    if (number == 0) {
    break;
    }
    sum += number;
    count++;
    }
    System.out.printf("平均 %.2f%n", sum / count);
    }
    }
    

    8.2异常与资源管理

    1. finally:无论try区块中有误发生异常,若有finally区块,则finally区块一定会被执行。

    2. Try-With-Resources:自动尝试关闭资源是协助关闭资源。

    3. ava.lang.AutoCloseable。

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    
    public class FileUtil {
    public static String readFile(String name) throws FileNotFoundException {
    StringBuilder text = new StringBuilder();
    try {
    Scanner console = new Scanner(new FileInputStream(name));
    while (console.hasNext()) {
    text.append(console.nextLine()).append('
    ');
    }
    } catch (FileNotFoundException ex) {
    ex.printStackTrace();
    throw ex;
    }
    return text.toString();
    }
    }
    
    public class Role1{
    private String name;
    private int level;
    private int blood;
    
    public int getBlood()
    {
    	return blood;
    }
    public void setBlood(int blood)
    {
    	this.blood = blood;
    }
    public int getLevel()
    {
    	return level;		
    }
    public void setLevel(int level)
    {
    	this.level = level;
    }
    public String getName()
    {
    	return name;
    }
    public void setName(String name)
    {
    	this.name = name;
    }
    
    }
    

    9.1Collection

    1. Collection架构:记录每个对象的索引顺序并能依索引取回对象,这样的行为定义在java.lang.list中;如果希望对象不重复,则由java.util.Set定义;如果以队列方式,使用java.lang.Queue。

    2. List:以索引方式保留收集对象的顺寻,操作类之一为java.lang.ArrayLis。

    3. Set:存在不收集相同对象的需求时,可以使用Set接口操作对象。java中判断对象是否重复时,都会调用hashcode()与equals()方法。

    4. Queue。

    5. Generics。

    6. Lambda。

    7. Interable Interator。

    8. Comparable Comparator。

    9.2Map

    1. Map操作类。

    2. 访问键值:HashMap、TreeMap为两个常用操作类。

    public class ForEach {
    public static void main(String[] args) {
    List names = Arrays.asList("Justin", "Monica", "Irene");
    forEach(names);
    forEach(new HashSet(names));
    forEach(new ArrayDeque(names));
    }
    static void forEach(Iterable iterable) {
    for (Object o : iterable) {
        System.out.println(o);
    }
    }
    }
    

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

    本周代码见代码托管https://git.oschina.net/nizaikanwoba/java-besti-is-2015-2016-2-20145225

    其他(感悟、思考等,)

    好好学。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积)
    目标 5000行 30篇 400小时
    第一周 150/150 2/2 15/15
    第二周 150/300 1/3 15/30
    第三周 200/500 1/4 15/45
    第四周 200/700 1/5 15/60
    第五周 200/900 1/6 15/75

    参考资料

  • 相关阅读:
    基础调试命令
    mui 拨打电话
    vue a href="tel" 拨打电话
    vue数据已渲染成 但还是报错 变量 undefined
    表格头部与左侧内容随滚动条位置改变而改变(基于jQuery)
    element popover 不显示/不隐藏问题解决方法
    fatal: The remote end hung up unexpectedly解决办法
    mui.fire 目标页无法监听到 触发事件
    多个定时器任务
    vue router 传参 获取不到query,params
  • 原文地址:https://www.cnblogs.com/nizaikanwoma/p/5351014.html
Copyright © 2020-2023  润新知