System 源码阅读
System
- 属性说明
/**
 *  System 类包含了几个有用的字段和方法,并且不能被实例化。
 *
 * @author  unascribed
 * @since   1.0
 */
public final class System {
    /* register the natives via the static initializer.
     *
     * VM will invoke the initializeSystemClass method to complete
     * the initialization for this class separated from clinit.
     * Note that to use properties set by the VM, see the constraints
     * described in the initializeSystemClass method.
     */
    private static native void registerNatives();
    static {
        registerNatives();
    }
    /** Don't let anyone instantiate this class */
    private System() {
    }
    /**
     *  标准输入流,默认为键盘
     */
    public static final InputStream in = null;
    /**
     *  标识输出流,默认为控制台
     */
    public static final PrintStream out = null;
    /**
     *  标准错误流,默认为控制台
     */
    public static final PrintStream err = null;
    /**
     *  此系统的安全管理器
     */
    private static volatile SecurityManager security;
    /**
     *  控制台
     */
    private static volatile Console cons;
    /**
     *  系统属性值
     *
     * The following properties are guaranteed to be defined:
     * <dl>
     * <dt>java.version         <dd>Java version number
     * <dt>java.version.date    <dd>Java version date
     * <dt>java.vendor          <dd>Java vendor specific string
     * <dt>java.vendor.url      <dd>Java vendor URL
     * <dt>java.vendor.version  <dd>Java vendor version
     * <dt>java.home            <dd>Java installation directory
     * <dt>java.class.version   <dd>Java class version number
     * <dt>java.class.path      <dd>Java classpath
     * <dt>os.name              <dd>Operating System Name
     * <dt>os.arch              <dd>Operating System Architecture
     * <dt>os.version           <dd>Operating System Version
     * <dt>file.separator       <dd>File separator ("/" on Unix)
     * <dt>path.separator       <dd>Path separator (":" on Unix)
     * <dt>line.separator       <dd>Line separator ("\n" on Unix)
     * <dt>user.name            <dd>User account name
     * <dt>user.home            <dd>User home directory
     * <dt>user.dir             <dd>User's current working directory
     * </dl>
     */
    private static Properties props;
- 输入输出流及控制台
    /**
     *  重设标准输入流
     *
     * @since   1.1
     */
    public static void setIn(InputStream in) {
        checkIO();
        setIn0(in);
    }
    /**
     *  重设标准输出流
     *
     * @param out   PrintStream 实例
     * @since   1.1
     */
    public static void setOut(PrintStream out) {
        checkIO();
        setOut0(out);
    }
    /**
     *  重设标准错误流
     *
     * @param err   PrintStream 实例
     * @since   1.1
     */
    public static void setErr(PrintStream err) {
        checkIO();
        setErr0(err);
    }
    private static native void setIn0(InputStream in);
    private static native void setOut0(PrintStream out);
    private static native void setErr0(PrintStream err);
- 读取系统属性和环境变量的值
    /**
     *  读取当前系统时序性
     *
     * <tr><th scope="row"><code>java.version</code></th>
     *     <td>Java Runtime Environment version, which may be interpreted
     *     as a {@link Runtime.Version}</td></tr>
     * <tr><th scope="row"><code>java.version.date</code></th>
     *     <td>Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD
     *     format, which may be interpreted as a {@link
     *     java.time.LocalDate}</td></tr>
     * <tr><th scope="row"><code>java.vendor</code></th>
     *     <td>Java Runtime Environment vendor</td></tr>
     * <tr><th scope="row"><code>java.vendor.url</code></th>
     *     <td>Java vendor URL</td></tr>
     * <tr><th scope="row"><code>java.vendor.version</code></th>
     *     <td>Java vendor version</td></tr>
     * <tr><th scope="row"><code>java.home</code></th>
     *     <td>Java installation directory</td></tr>
     * <tr><th scope="row"><code>java.vm.specification.version</code></th>
     *     <td>Java Virtual Machine specification version which may be
     *     interpreted as a {@link Runtime.Version}</td></tr>
     * <tr><th scope="row"><code>java.vm.specification.vendor</code></th>
     *     <td>Java Virtual Machine specification vendor</td></tr>
     * <tr><th scope="row"><code>java.vm.specification.name</code></th>
     *     <td>Java Virtual Machine specification name</td></tr>
     * <tr><th scope="row"><code>java.vm.version</code></th>
     *     <td>Java Virtual Machine implementation version which may be
     *     interpreted as a {@link Runtime.Version}</td></tr>
     * <tr><th scope="row"><code>java.vm.vendor</code></th>
     *     <td>Java Virtual Machine implementation vendor</td></tr>
     * <tr><th scope="row"><code>java.vm.name</code></th>
     *     <td>Java Virtual Machine implementation name</td></tr>
     * <tr><th scope="row"><code>java.specification.version</code></th>
     *     <td>Java Runtime Environment specification version which may be
     *     interpreted as a {@link Runtime.Version}</td></tr>
     * <tr><th scope="row"><code>java.specification.vendor</code></th>
     *     <td>Java Runtime Environment specification  vendor</td></tr>
     * <tr><th scope="row"><code>java.specification.name</code></th>
     *     <td>Java Runtime Environment specification  name</td></tr>
     * <tr><th scope="row"><code>java.class.version</code></th>
     *     <td>Java class format version number</td></tr>
     * <tr><th scope="row"><code>java.class.path</code></th>
     *     <td>Java class path</td></tr>
     * <tr><th scope="row"><code>java.library.path</code></th>
     *     <td>List of paths to search when loading libraries</td></tr>
     * <tr><th scope="row"><code>java.io.tmpdir</code></th>
     *     <td>Default temp file path</td></tr>
     * <tr><th scope="row"><code>java.compiler</code></th>
     *     <td>Name of JIT compiler to use</td></tr>
     * <tr><th scope="row"><code>os.name</code></th>
     *     <td>Operating system name</td></tr>
     * <tr><th scope="row"><code>os.arch</code></th>
     *     <td>Operating system architecture</td></tr>
     * <tr><th scope="row"><code>os.version</code></th>
     *     <td>Operating system version</td></tr>
     * <tr><th scope="row"><code>file.separator</code></th>
     *     <td>File separator ("/" on UNIX)</td></tr>
     * <tr><th scope="row"><code>path.separator</code></th>
     *     <td>Path separator (":" on UNIX)</td></tr>
     * <tr><th scope="row"><code>line.separator</code></th>
     *     <td>Line separator ("\n" on UNIX)</td></tr>
     * <tr><th scope="row"><code>user.name</code></th>
     *     <td>User's account name</td></tr>
     * <tr><th scope="row"><code>user.home</code></th>
     *     <td>User's home directory</td></tr>
     * <tr><th scope="row"><code>user.dir</code></th>
     *     <td>User's current working directory</td></tr>
     * <p>
     *
     * @implNote In addition to the standard system properties, the system
     * properties may include the following keys:
     * <table class="striped">
     * <caption style="display:none">Shows property keys and associated values</caption>
     * <thead>
     * <tr><th scope="col">Key</th>
     *     <th scope="col">Description of Associated Value</th></tr>
     * </thead>
     * <tbody>
     * <tr><th scope="row">{@code jdk.module.path}</th>
     *     <td>The application module path</td></tr>
     * <tr><th scope="row">{@code jdk.module.upgrade.path}</th>
     *     <td>The upgrade module path</td></tr>
     * <tr><th scope="row">{@code jdk.module.main}</th>
     *     <td>The module name of the initial/main module</td></tr>
     * <tr><th scope="row">{@code jdk.module.main.class}</th>
     *     <td>The main class name of the initial module</td></tr>
     * </tbody>
     * </table>
     */
    public static Properties getProperties() {
        final SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPropertiesAccess();
        }
        return props;
    }
    /**
     *  读取指定名称的系统属性
     *
     * @param      key  系统属性的名称
     */
    public static String getProperty(String key) {
        checkKey(key);
        final SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPropertyAccess(key);
        }
        return props.getProperty(key);
    }
    /**
     *  读取指定名称 key 的系统属性值,如果不存在,则使用默认值
     *
     * @param      key  系统属性的名称
     * @param      def  默认值
     */
    public static String getProperty(String key, String def) {
        checkKey(key);
        final SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPropertyAccess(key);
        }
        return props.getProperty(key, def);
    }
    /**
     *  获取当前系统的环境变量映射
     *
     * @since  1.5
     */
    public static java.util.Map<String,String> getenv() {
        final SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("getenv.*"));
        }
        return ProcessEnvironment.getenv();
    }
    /**
     *  读取指定名称的环境变量
     *
     * @param  name 环境变量名称
     */
    public static String getenv(String name) {
        final SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("getenv."+name));
        }
        return ProcessEnvironment.getenv(name);
    }
- 其他常用方法
    /**
     *  将源数组的子数组拷贝到目标数组中
     *
     * @param      src      源数组
     * @param      srcPos   源数组起始索引,包括
     * @param      dest     目标数组
     * @param      destPos  目标数组起始索引,包括
     * @param      length   从源数组拷贝的元素个数
     */
    @HotSpotIntrinsicCandidate
    public static native void arraycopy(Object src,  int  srcPos,
            Object dest, int destPos,
            int length);
    /**
     *  返回当前 JVM 关联的控制台
     *
     * @since   1.6
     */
    public static Console console() {
        Console c;
        if ((c = cons) == null) {
            synchronized (System.class) {
                if ((c = cons) == null) {
                    cons = c = SharedSecrets.getJavaIOAccess().console();
                }
            }
        }
        return c;
    }
    /**
     *  1970-01-01 UTC 午夜到此刻之间的毫秒数
     */
    @HotSpotIntrinsicCandidate
    public static native long currentTimeMillis();
    /**
     *  返回当前虚拟机高分辨率的时间源,以纳秒为单位,只能用于计算时间差
     *
     * @since 1.5
     */
    @HotSpotIntrinsicCandidate
    public static native long nanoTime();
    /**
     *  主动终止当前虚拟机,非 0 的退出状态表示异常终止。
     *
     * @param      status   退出状态值
     */
    public static void exit(int status) {
        Runtime.getRuntime().exit(status);
    }
    /**
     *  主动运行垃圾收集器,不建议调用
     */
    public static void gc() {
        Runtime.getRuntime().gc();
    }
    /**
     *  计算指定对象的哈希值,null 对象为 0
     *
     * @param x 待计算哈希值的目标对象
     * @since   1.1
     */
    @HotSpotIntrinsicCandidate
    public static native int identityHashCode(Object x);
System 源码阅读的更多相关文章
- 【原】FMDB源码阅读(二)
		[原]FMDB源码阅读(二) 本文转载请注明出处 -- polobymulberry-博客园 1. 前言 上一篇只是简单地过了一下FMDB一个简单例子的基本流程,并没有涉及到FMDB的所有方方面面,比 ... 
- [Erlang 0119] Erlang OTP 源码阅读指引
		上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的? "代码去哪里找?",关于Erla ... 
- Android源码阅读 – Zygote
		@Dlive 本文档: 使用的Android源码版本为:Android-4.4.3_r1 kitkat (源码下载: http://source.android.com/source/index.ht ... 
- EventBus源码解析 源码阅读记录
		EventBus源码阅读记录 repo地址: greenrobot/EventBus EventBus的构造 双重加锁的单例. static volatile EventBus defaultInst ... 
- 如何阅读Java源码 阅读java的真实体会
		刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比 ... 
- SparkConf加载与SparkContext创建(源码阅读一)
		即日起开始spark源码阅读之旅,这个过程是相当痛苦的,也许有大量的看不懂,但是每天一个方法,一点点看,相信总归会有极大地提高的.那么下面开始: 创建sparkConf对象,那么究竟它干了什么了类,从 ... 
- java8 ArrayList源码阅读
		转载自 java8 ArrayList源码阅读 本文基于jdk1.8 JavaCollection库中有三类:List,Queue,Set 其中List,有三个子实现类:ArrayList,Vecto ... 
- CI框架源码阅读笔记5 基准测试 BenchMark.php
		上一篇博客(CI框架源码阅读笔记4 引导文件CodeIgniter.php)中,我们已经看到:CI中核心流程的核心功能都是由不同的组件来完成的.这些组件类似于一个一个单独的模块,不同的模块完成不同的功 ... 
- CI框架源码阅读笔记4 引导文件CodeIgniter.php
		到了这里,终于进入CI框架的核心了.既然是“引导”文件,那么就是对用户的请求.参数等做相应的导向,让用户请求和数据流按照正确的线路各就各位.例如,用户的请求url: http://you.host.c ... 
随机推荐
- IIS出现Server Error in '/' Application 错误的解决办法
			C:\Windows\Temp"文件夹加上 IIS_IUSRS的权限 
- promises的深入学习
			Promise 的含义 § ⇧ Promise 是异步编程的一种解决方案,比传统的解决方案——回调函数和事件——更合理和更强大.它由社区最早提出和实现,ES6 将其写进了语言标准,统一了用法,原生提供 ... 
- 关于SAMBA的关键参考资源
			https://www.samba.org/samba/docs/man/ https://devel.samba.org/ http://www.ubiqx.org/cifs/ https://ww ... 
- Samba set of user authentication and file access rights
			This series is compatible with Linux certification exam LPIC. A typical Linux user-level topics omit ... 
- 制作CentOS8安装U盘时遇到的“Minimal BASH-like...”问题
			---恢复内容开始--- CentOS8已经推出了,正好最近新到了块服务器硬盘需要安装系统,就拿过来尝一下鲜. 下载好iso文件后,以制作CentOS7安装盘相同的步骤,用UltroISO(软碟通)往 ... 
- Vi 入门简易教程
			首先,请注意,以下所讲的,全部是键盘在英文输入模式下.如果键盘是在中文输 入模式,全部的指令不正确. vi 有两种模式: Command Mode(指令模式) and Insert Mode(我姑且称 ... 
- Bridge 桥梁模式
			注:桥梁模式是结构型设计模式,将抽象部分与它的实现部分相分离,使他们可以独立的变化. 抽象部分可能有n种实现,而实现部分可能有n种实现方式,采用享元模式,减少子类数据. 曾经看过一个桥梁模式相关的例 ... 
- SpringBoot 如何实现自动配置
			SpringMVC 和 SpringBoot 都是基于Spring的,两者推出的时间相差不大,只不过是SpringMVC推出早点. 关于两者,最近看到一个比较通俗的讲法: Spring 最初利用“工厂 ... 
- UVa136 Ugly Numbers(优先队列priority_queue)
			Ugly Numbers 题目 Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, ... 
- 【技巧  二进制分组】bzoj4398: 福慧双修&&2407: 探险
			二进制分组也可以说是一种比较优美的拆贡献方式吧? Description 菩萨为行,福慧双修,智人得果,不忘其本.——唐朠立<大慈恩寺三藏法师传>有才而知进退,福慧双修,这才难得.——乌雅 ... 
