Java进阶笔记

760 阅读1分钟

进阶

  • char类型占两个字节,16位,一个十六进制的数可以代替四个二进制的数

image.png

  • && 与 & 的区别

image.png

image.png

  • properties文件;

抽象类:可以具体,可以抽象

public abstract class Person(){
    public abstract void say();//做接口
    public void say1(){
        ...
    }

}

具体类:不可以抽象

异常机制

  • 检测异常
public static void fn1(){
    throw new Exception("")
}

上述代码报错 方式一:捕获

public static void fn1(){
    try{
        throw new Exception("");
    }catch(Exception e){
    
    }
}

方式二:外抛,抛到调用函数处,交给调用他的函数处理

public static void fn1() throws Exception{
    try{
        throw new Exception("");
    }catch(Exception e){
        throw new Exception("");
    }
}

RuntimeException及其子类为非检测异常,不需要显式处理

public static void fn1(){
    throw new RuntimeException(e);
}

上面代码不需要抛出异常