推荐淘宝秋冬男装热卖网店

追求无止境

我的程序人生
随笔 - 31, 文章 - 2, 评论 - 20, 引用 - 0
数据加载中……

Java DOC学习笔记

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

posted on 2009-11-16 13:11 追求无止境 阅读(136) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: