类加载(二)


1.Class 的getClassLoader()

  Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader.

This method will return null in such implementations if this class was loaded by the bootstrap class loader.

2.Thread 的getContextClassLoader()

  Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator of the thread for

use by code running in this thread when loading classes and resources. If not set, the default is the ClassLoadercontext

of the parent Thread. The context ClassLoader of the primordial thread is typically set to the class loader used to load

the application.

  For example,JNDI and JAXP used thread's ClassLoader.You had better to use thread's ClassLoader in your own code when your

code need to deployed on J2EE container.

3.ClassLoader.getResourceAsStream() 与 Class.getResourceAsStream()的区别

Class.getResourceAsStream()

  Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining

class loaderof the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader,

the method delegates toClassLoader.getSystemResourceAsStream(java.lang.String).Before delegation, an absolute resource name is

constructed from the given resource name using this algorithm:

  • If thenamebegins with a'/'('\u002f'), then the absolute name of the resource is the portion of thenamefollowing the'/'.
  • Otherwise, the absolute name is of the following form:
    modified_package_name/name

    Where themodified_package_nameis the package name of this object with'/'substituted for'.'('\u002e').

优质内容筛选与推荐>>
1、安装东皇mac 问题集
2、数据结构练习(21)字符串的排列
3、Android——监听事件总结
4、初识AngularJS
5、luogu_1196 银河英雄传说


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号