1、Interface Comparable<T>
只有實現該接口的對象的列表或數組才能調用Collections.sort()方法。
在實現 int compareTo(T o)時,需要注意:
1、如果兩個對象相等,返回為0;
2、如果同一個null對象進行比較,應拋出NullPointerException。
3、實現必須保證sgn(x.compareTo(y)) == -sgn(y.compareTo(x))、(x.compareTo(y)==0) == (x.equals(y)) 、(x.compareTo(y)>0 && y.compareTo(z)>0) impliesx.compareTo(z)>0 。如果 x.compareTo(y)拋出異常,y.compareTo(x)也必須拋出異常。
2、Interface Iterable<T>
Iterator<T>
iterator()
對于鏈表等對象應實現該接口來允許一個對象可以使用foreach語句。
上面的方法返回java.util.Interface Iterator<E>,該接口的主要方法有:
hasNext();next();remove();
3、Interface Readable
java.lang.Interface Readable
一個Readable 是一個字符串的來源。實現這個接口需要實現的方法是:
int
read(CharBuffer cb)
4、
java.lang Interface Runnable
不用說,這個誰都知道。如果想在一個單獨的線程中執行,就需要實現這個接口。
5、java.lang Interface Thread.UncaughtExceptionHandler
從名字就可以判斷出來,當線程拋出未捕獲的異常時,實現這個接口的類的對象可以對一場進行處理。
官方文檔:當線程被一個未捕獲的異常打斷時,這個接口被調用。
當線程要被為捕獲異常打斷是,JVM使用Thread.getUncaughtExceptionHandler(),查詢異常處理器,如果線程沒有這個接口的設置,則查詢該線程的ThreadGroup的UncaughtExceptionHandler,如果縣城沒有處理異常,他就會拋出這個異常。
void
uncaughtException(Thread t, Throwable e)
Method invoked when the given thread terminates due to the given uncaught exception.
6、包裝型對象:Boolean Byte Character Double Float Long Short Integer
這些類就不用了說了,主要會使用里面的靜態方法和一些常量就可以了。
7、Class Character.Subset
這個類的實例代表了Unicode字符集的特殊的子集。定義在Character中的唯一子集族類是UnicodeBlock.其他的Java API或許因為自己的用戶定義了其他的子集。
static Character.UnicodeBlock
AEGEAN_NUMBERS
Constant for the "Aegean Numbers" Unicode character block.
static Character.UnicodeBlock
ALPHABETIC_PRESENTATION_FORMS
Constant for the "Alphabetic Presentation Forms" Unicode character block.
static Character.UnicodeBlock
ARABIC
Constant for the "Arabic" Unicode character block.
static Character.UnicodeBlock
ARABIC_PRESENTATION_FORMS_A
Constant for the "Arabic Presentation Forms-A" Unicode character block.
static Character.UnicodeBlock
ARABIC_PRESENTATION_FORMS_B
Constant for the "Arabic Presentation Forms-B" Unicode character block.
static Character.UnicodeBlock
ARMENIAN
Constant for the "Armenian" Unicode character block.
static Character.UnicodeBlock
ARROWS
Constant for the "Arrows" Unicode character block.
static Character.UnicodeBlock
BASIC_LATIN
Constant for the "Basic Latin" Unicode character block.
static Character.UnicodeBlock
BENGALI
Constant for the "Bengali" Unicode character block.
static Character.UnicodeBlock
BLOCK_ELEMENTS
Constant for the "Block Elements" Unicode character block.
static Character.UnicodeBlock
BOPOMOFO
Constant for the "Bopomofo" Unicode character block.
static Character.UnicodeBlock
BOPOMOFO_EXTENDED
Constant for the "Bopomofo Extended" Unicode character block.
static Character.UnicodeBlock
BOX_DRAWING
Constant for the "Box Drawing" Unicode character block.
…………
具體參見java.lang
Class Character.UnicodeBlock里面的定義。
8 、java.langClass Class<T>
這個類的實力代表了Java運行程序中的類和接口。Enum是類,而Annotation是一個接口。Every array also belongs to a class that is reflected as a Class
object that is shared by all arrays with the same element type and number of dimensions.
Class的對象在程序中可以獲取類的詳細信息。
9、Java.lang.Class ClassLoader
ClassLoader是個不錯的東西,下面是官方文檔的簡單翻譯和注解:
1、ClassLoader用于加載類對象。ClassLoader是一個抽象類。給出類的二進制名字(如“
"java.lang.String"
"javax.swing.JSpinner$DefaultEditor"
"java.security.KeyStore$Builder$FileBuilder$1"
"java.net.URLClassLoader$3$1"
”),ClassLoader會使用定位和生成類。一個典型的策略就是將二進制名字轉化為文件名,然后從文件系統中讀取這個類文件。
每一個Class對象都包含了一個創建它的引用。
數組的Class對象不能由ClassLoader創建,但是可以由Java運行時動態創建。一個數組類的ClassLoader,和他的元素的ClassLoader是一樣的;如果元素是基本類型,則數組類沒有ClassLoader。
應用程序可以實現ClassLoader的子類,來擴展行為。這樣可以在JVM動態的創建類。
ClassLoader主要由安全管理器來使用,用于保證安全區域。
ClassLoader 使用一個delegation(委托)模型來搜索類和資源。每一個ClassLoader有一個相關的父類ClassLoader。當請求來查找一個資源或者類的時候,ClassLoader 實例會委托搜索類和資源。
內建的ClassLoader,叫做bootstrap class loader,沒有父類。
正常的,ClassLoader從本地文件系統中加載數據。通過CLassPath。
當然,也可以通過NetWork從服務器上下載字節碼。來加載類:
ClassLoader loader = new NetworkClassLoader(host, port);
Object main = loader.loadClass("Main", true).newInstance();
Network ClassLoader 子類必須定義方法FindClass 和loadClassData來加載來自互聯網上的類。一旦或得到字節碼,它使用defineClass方法來創建類實例。
class NetworkClassLoader extends ClassLoader {
String host;
int port;
public Class findClass(String name) {
byte[] b = loadClassData(name);
return defineClass(name, b, 0, b.length);
}
private byte[] loadClassData(String name) {
// load the class data from the connection . . .
}
}
個人理解:
ClassLoader是一個類加載器,除了可以從ClassPath加載類之外,還可以從ClassPath中加載資源:
InputStream
getResourceAsStream(String name)
Returns an input stream for reading the specified resource.
Enumeration<URL>
getResources(String name)
Finds all the resources with the given name.
static URL
getSystemResource(String name)
Find a resource of the specified name from the search path used to load classes.
static InputStream
getSystemResourceAsStream(String name)
Open for reading, a resource of the specified name from the search path used to load classes.
static Enumeration<URL>
getSystemResources(String name)
Finds all resources of the specified name from the search path used to load classes.
protected Class<?>
findClass(String name)
Finds the class with the specified binary name.
10、Compiler類3
編譯類是提供給支持Java到本地代碼編譯器和相關服務。根據設計,編譯器類什么都不做;它作為一個占位符來為運行時編譯執行的技術。
當JVM第一次啟動時,他判斷java.compiler是否存在。如果存在,他3