推薦淘寶秋冬男裝熱賣網(wǎng)店

          追求無(wú)止境

          我的程序人生
          隨筆 - 31, 文章 - 2, 評(píng)論 - 20, 引用 - 0
          數(shù)據(jù)加載中……

          Java DOC學(xué)習(xí)筆記

          1、Interface Comparable<T>

          只有實(shí)現(xiàn)該接口的對(duì)象的列表或數(shù)組才能調(diào)用Collections.sort()方法。

          在實(shí)現(xiàn) int compareTo(T o)時(shí),需要注意:

          1、如果兩個(gè)對(duì)象相等,返回為0;

          2、如果同一個(gè)null對(duì)象進(jìn)行比較,應(yīng)拋出NullPointerException。

          3、實(shí)現(xiàn)必須保證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()

          對(duì)于鏈表等對(duì)象應(yīng)實(shí)現(xiàn)該接口來(lái)允許一個(gè)對(duì)象可以使用foreach語(yǔ)句。

          上面的方法返回java.util.Interface Iterator<E>,該接口的主要方法有:

          hasNext();next();remove();

          3、Interface Readable

          java.lang.Interface Readable

                一個(gè)Readable 是一個(gè)字符串的來(lái)源。實(shí)現(xiàn)這個(gè)接口需要實(shí)現(xiàn)的方法是:

          int read(CharBuffer cb)

          4、java.lang  Interface Runnable

          不用說(shuō),這個(gè)誰(shuí)都知道。如果想在一個(gè)單獨(dú)的線程中執(zhí)行,就需要實(shí)現(xiàn)這個(gè)接口。

          5、java.lang Interface Thread.UncaughtExceptionHandler

                 從名字就可以判斷出來(lái),當(dāng)線程拋出未捕獲的異常時(shí),實(shí)現(xiàn)這個(gè)接口的類的對(duì)象可以對(duì)一場(chǎng)進(jìn)行處理。

                官方文檔:當(dāng)線程被一個(gè)未捕獲的異常打斷時(shí),這個(gè)接口被調(diào)用。

                當(dāng)線程要被為捕獲異常打斷是,JVM使用Thread.getUncaughtExceptionHandler(),查詢異常處理器,如果線程沒(méi)有這個(gè)接口的設(shè)置,則查詢?cè)摼€程的ThreadGroup的UncaughtExceptionHandler,如果縣城沒(méi)有處理異常,他就會(huì)拋出這個(gè)異常。

          void uncaughtException(Thread t, Throwable e)
                    Method invoked when the given thread terminates due to the given uncaught exception.

          6、包裝型對(duì)象:Boolean Byte Character Double Float Long Short Integer

              這些類就不用了說(shuō)了,主要會(huì)使用里面的靜態(tài)方法和一些常量就可以了。

          7、Class Character.Subset

             這個(gè)類的實(shí)例代表了Unicode字符集的特殊的子集。定義在Character中的唯一子集族類是UnicodeBlock.其他的Java API或許因?yàn)樽约旱挠脩舳x了其他的子集。

          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.

          …………

          具體參見(jiàn)java.lang
          Class Character.UnicodeBlock里面的定義。

          8 、java.langClass Class<T>

          這個(gè)類的實(shí)力代表了Java運(yùn)行程序中的類和接口。Enum是類,而Annotation是一個(gè)接口。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的對(duì)象在程序中可以獲取類的詳細(xì)信息。

          9、Java.lang.Class ClassLoader

          ClassLoader是個(gè)不錯(cuò)的東西,下面是官方文檔的簡(jiǎn)單翻譯和注解:

          1、ClassLoader用于加載類對(duì)象。ClassLoader是一個(gè)抽象類。給出類的二進(jìn)制名字(如“

            "java.lang.String"
             "javax.swing.JSpinner$DefaultEditor"
             "java.security.KeyStore$Builder$FileBuilder$1"
             "java.net.URLClassLoader$3$1"

          ”),ClassLoader會(huì)使用定位和生成類。一個(gè)典型的策略就是將二進(jìn)制名字轉(zhuǎn)化為文件名,然后從文件系統(tǒng)中讀取這個(gè)類文件。

          每一個(gè)Class對(duì)象都包含了一個(gè)創(chuàng)建它的引用。

          數(shù)組的Class對(duì)象不能由ClassLoader創(chuàng)建,但是可以由Java運(yùn)行時(shí)動(dòng)態(tài)創(chuàng)建。一個(gè)數(shù)組類的ClassLoader,和他的元素的ClassLoader是一樣的;如果元素是基本類型,則數(shù)組類沒(méi)有ClassLoader。

          應(yīng)用程序可以實(shí)現(xiàn)ClassLoader的子類,來(lái)擴(kuò)展行為。這樣可以在JVM動(dòng)態(tài)的創(chuàng)建類。

          ClassLoader主要由安全管理器來(lái)使用,用于保證安全區(qū)域。

          ClassLoader 使用一個(gè)delegation(委托)模型來(lái)搜索類和資源。每一個(gè)ClassLoader有一個(gè)相關(guān)的父類ClassLoader。當(dāng)請(qǐng)求來(lái)查找一個(gè)資源或者類的時(shí)候,ClassLoader 實(shí)例會(huì)委托搜索類和資源。

          內(nèi)建的ClassLoader,叫做bootstrap class loader,沒(méi)有父類。

          正常的,ClassLoader從本地文件系統(tǒng)中加載數(shù)據(jù)。通過(guò)CLassPath。

          當(dāng)然,也可以通過(guò)NetWork從服務(wù)器上下載字節(jié)碼。來(lái)加載類:

          ClassLoader loader = new NetworkClassLoader(host, port);
          Object main = loader.loadClass("Main", true).newInstance();
          Network ClassLoader 子類必須定義方法FindClass 和loadClassData來(lái)加載來(lái)自互聯(lián)網(wǎng)上的類。一旦或得到字節(jié)碼,它使用defineClass方法來(lái)創(chuàng)建類實(shí)例。
          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  . . .
                   }
               }

          個(gè)人理解:

          ClassLoader是一個(gè)類加載器,除了可以從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到本地代碼編譯器和相關(guān)服務(wù)。根據(jù)設(shè)計(jì),編譯器類什么都不做;它作為一個(gè)占位符來(lái)為運(yùn)行時(shí)編譯執(zhí)行的技術(shù)。

          當(dāng)JVM第一次啟動(dòng)時(shí),他判斷java.compiler是否存在。如果存在,他3

          posted on 2009-11-16 13:11 追求無(wú)止境 閱讀(147) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 通化县| 博客| 响水县| 措美县| 政和县| 九寨沟县| 西华县| 乡宁县| 周宁县| 宁化县| 祁门县| 福鼎市| 凤台县| 马鞍山市| 万安县| 深水埗区| 紫阳县| 恭城| 南木林县| 红桥区| 浪卡子县| 苍山县| 长沙县| 海门市| 金平| 义马市| 景宁| 麻江县| 新乡市| 定结县| 通化市| 张家界市| 交城县| 武平县| 全州县| 瑞丽市| 新干县| 东至县| 芦溪县| 邵阳县| 南平市|