读Java 804 - Quick refresher

  • Upcast永远是成功的,但Downcast不是,记得作instanceof判断
  • 仅抛不一样异常,而返回值相同的重载是不能够的
  • static import只会import静态类
  • static method内不能使用this和super,不能用super!
  • 只有static nested class能有静态成员,其它nested不能有,且静态嵌入类能够访问外围类的私有成员但仅限于静态成员
  • 不能够在enums前使用new(由于其构造函数是私有的)
  • 枚举默认且只能为public static final,因此不能继承
  • 接口里面的变量必须被初始化,并且是final的
  • 接口里面不能有BODY,所有为public abstract
  • 接口能够有nested interface,这时的内嵌的接口能够为private/protected or public
  • is-a (实现/继承) is-like-a(接口),has-a(组合)
  • 泛型不支持协变,again, List<SuperT> lst = new List<T>() 会出错
  • <? extends T> 指必须在T的scope内,至关于c#的(?), <? super T> 指的是T必须为继承了T,好比<? super Path>
  • 没有泛型异常这回事,即没有这种东西 -> GenericExeption<T> extends Throwable
  • 泛型类型不能够为primitive
  • 使用HashSet/HashMap时要重写hashCode()和equals()
  • 关于泛型呢,由于是type erasure因此没有预先定义这回事,因此静态泛型(static T xxx) 是不存在的,
  • %o: octual 八进制  %x: hexadecimal 16进制
  • Watch service不会递归watch子目录,须要本身resursively register watch key
  • If the JDBC API is not able to locate the JDBC driver, it will throw a SQLException. If there are jars for the drivers available, they need to be included in the classpath to enable the JDBC API to locate the driverjava

  • ResultSet一开始游标指向的是第一条前面,因此必须运行.next()拿到第一条正则表达式

  • RowSet是种特殊的支持JavaBean组件的ResultSet
        JdbcRowSet: 
        CachedRowSet: disconnected ResultSet
            WebRowSet: CachedRowset + XML (没有说这个是JSON格式喔)
                JoinRowSet: WebRowset + SQL join
                FilteredRowSet: WebRowset + filteringc#

  • JDBC 4.1 introduces the capability to use try-with-resources statement to close resources (Connection, ResultSet,and Statement) automatically.oracle

  • try-catch的异常若是相似并且处理方式也相似的话,能够考虑使用multi-catch块 app

  • 即便在catch中return了,也仍是会执行到finally的,除非执行的是system.exit(n), 由于这个是停掉全部包括其它的dom

  • static initialization block cannot throw any checked exceptions. now-static initialization blocks can. however, all the constructors should declare that exception in their throws clauseide

  • 重写的方法中throw的异常只能比父类的异常更具体,而不能更宽泛,或者不throws也是能够的函数

  • 若是方法在实现的多个接口中都存在且抛出的异常不一样,则实现的方法应该同时抛出这些异常this

  • 自定义exception最后继承于Exception或RuntimeException,而不要直接继承Throwable,这个是JVM预留的spa

  • bundlename_language_country_#script.properties

  • Format (抽象类)
        NumberFormat
        DateFormat - 大写W/D/F(day of week)的是in year, 小写w/d/f的是in month,大写S是毫秒,大写K是am/pm小时数,小写k是hour (1-24), H是(0-23)
            SimpleDateFormat

  • sleep(): 不会release the lock,会hold on to the lock

  • join(): wait for another thread to terminate

  • 仍然不懂的:


  • static method 不能够被override

  • 接口里的方法只能为public & abstract,不然会出编译错“Illegal modifier for the interface method say; only public & abstract are permitted”

    接口里面的field只能为public, final & static,不然会出编译错“Illegal modifier for the interface field Foo.iVisual; only public, static & final are permitted”

  • 前期绑定和后期绑定

  • static block: A constructor will be invoked when an instance of the class is created, while the static block will be invoked when the program initializes

  • 抽象类能够有静态类
  • static的目标不可使用this,由于它不属于任何一个实例
  • 静态方法里面不可使用super.StaticMethod(),既然它不能够被继承,也不能使用super了
  • nested class:
    若是内嵌方法是static的,则使用new A.B()
    若是外围方法是static的,则使用new A().B()
    new A().B().C();
    抽象类中的内嵌方法,由于没有实例,因此能够直接A.new B()或A.this.method();
    记住实例方法必定要有实例,不然要new()
    没有static外围类这回事内部类自动拥有对其外围类的全部成员的访问权, 若是内部类和外部类成员的名字彻底相同,则在内部类方法中要访问外部类成员(即便是private的),
    内部类必须声明为protected, default, public才对外围类可见(private则会编译错显示为is not visible),
  • a. 内部类能够访问private
    b. 内部类成员能够与外围类同名
  • 内部类不能够有static变量但能够有常量即static final
  • 内部方法类的参数只能为final
  • 匿名类必定是定义在实例化后的对象内的,即 Foo f = new Foo(){ public void say(){ .. } }; 或Foo f {return new Foo(){ public void say(){};}}
  • 匿名类没有显式构造函数,也不能有构造函数
  • Enum类型的constructor只能被定义为private
  • Enum类型的enum常量的定义必须是在第一行...
  • Enums被隐式定义为public, static, final,不可被继承
  • 全部enum都会被转换为类:因此TryEnums.SomeEnum.valueOf("TEST1").getClass()
  • 全部enum类型都继承于java.lang.Enum,每一个enum元素都会被转换为enum类的常量,见enum定义 TryEnums.SomeEnum et = TryEnums.SomeEnum.TEST1; 
  • 接口内部类自动都是public static的,至关于为接口定义了一种变量类型

  • TryEnums.SomeEnum et = TryEnums.SomeEnum.TEST1;

    System.out.println(et.TEST2); // et定义为一个静态类的常量后,仍然能够用et.TEST2来取到TEST2的常量

  • 由于enum是final static public的,因此不能定义在local inter class中

  • FileWriter fw = FileWriter(path, boolean isAppend)
    fw.append("test001");
    fw.close();
    若是没有第二个boolean参数,默认为覆盖写。

  • A setAutoCommit (False) method invocation starts a transaction context.

  • 看一下正则表达式
    \\s* matches 0 or more occurrences of whitespaces.

  • ScheduledExecutorService

  • The method used to obtain the Executor determines how many Threads are used to execute tasks.

  • 看集合类图,象Q144

  • Class Hashtable extends Dictionary implements Serializable, Cloneable, Map。

    Interface SortedMap extends Map

  • Change FileReader to BufferReader.

    public class BufferedReader extends Reader

    Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

    The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

  • ThreadLocalRandom.current().nextInt(1, 101);   

相关文章
相关标签/搜索