文档章节

System.getProperty("os.name")这里的key对应的value是哪里取值呢?

writeademo
 writeademo
发布于 2017/04/04 23:16
字数 1132
阅读 40
收藏 1

 

System.getProperty("os.name")这里的key对应的value是哪里取值呢?

 

 

 

 

 

 

 

从这里可以看出是jvm自己默认的一些属性设置。

      System.out.println(System.getProperty("os.name"));

           System.out.println(System.getProperty("sun.boot.class.path"));

           System.out.println(System.getProperty("java.ext.dirs"));

           System.out.println(System.getProperty("awt.toolkit"));

           System.setProperty("my", "123");

           System.out.println(System.getProperty("my"));

 

也可以自定义设置key-value;

  public static String getProperty(String key) {

        checkKey(key);

        SecurityManager sm = getSecurityManager();

        if (sm != null) {

            sm.checkPropertyAccess(key);

        }

 

        return props.getProperty(key);

}

 

  public String getProperty(String key) {

        Object oval = super.get(key);

        String sval = (oval instanceof String) ? (String)oval : null;

        return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;

    }

 

@SuppressWarnings("unchecked")

    public synchronized V get(Object key) {

        Entry<?,?> tab[] = table;

        int hash = key.hashCode();

        int index = (hash & 0x7FFFFFFF) % tab.length;

        for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {

            if ((e.hash == hash) && e.key.equals(key)) {

                return (V)e.value;

            }

        }

        return null;

    }         

    /**

     * The hash table data.

     */

    private transient Entry<?,?>[] table;

 

 

    /**

     * Hashtable bucket collision list entry

     */

    private static class Entry<K,V> implements Map.Entry<K,V> {

        final int hash;

        final K key;

        V value;

        Entry<K,V> next;

 

        protected Entry(int hash, K key, V value, Entry<K,V> next) {

            this.hash = hash;

            this.key =  key;

            this.value = value;

            this.next = next;

        }

 

        @SuppressWarnings("unchecked")

        protected Object clone() {

            return new Entry<>(hash, key, value,

                                  (next==null ? null : (Entry<K,V>) next.clone()));

        }

 

        // Map.Entry Ops

 

        public K getKey() {

            return key;

        }

 

        public V getValue() {

            return value;

        }

 

        public V setValue(V value) {

            if (value == null)

                throw new NullPointerException();

 

            V oldValue = this.value;

            this.value = value;

            return oldValue;

        }

 

        public boolean equals(Object o) {

            if (!(o instanceof Map.Entry))

                return false;

            Map.Entry<?,?> e = (Map.Entry<?,?>)o;

 

            return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&

               (value==null ? e.getValue()==null : value.equals(e.getValue()));

        }

 

        public int hashCode() {

            return hash ^ Objects.hashCode(value);

        }

 

        public String toString() {

            return key.toString()+"="+value.toString();

        }

    }

 

    interface Entry<K,V> {

        /**

         * Returns the key corresponding to this entry.

         *

         * @return the key corresponding to this entry

         * @throws IllegalStateException implementations may, but are not

         *         required to, throw this exception if the entry has been

         *         removed from the backing map.

         */

        K getKey();

 

        /**

         * Returns the value corresponding to this entry.  If the mapping

         * has been removed from the backing map (by the iterator's

         * <tt>remove</tt> operation), the results of this call are undefined.

         *

         * @return the value corresponding to this entry

         * @throws IllegalStateException implementations may, but are not

         *         required to, throw this exception if the entry has been

         *         removed from the backing map.

         */

        V getValue();

 

        /**

         * Replaces the value corresponding to this entry with the specified

         * value (optional operation).  (Writes through to the map.)  The

         * behavior of this call is undefined if the mapping has already been

         * removed from the map (by the iterator's <tt>remove</tt> operation).

         *

         * @param value new value to be stored in this entry

         * @return old value corresponding to the entry

         * @throws UnsupportedOperationException if the <tt>put</tt> operation

         *         is not supported by the backing map

         * @throws ClassCastException if the class of the specified value

         *         prevents it from being stored in the backing map

         * @throws NullPointerException if the backing map does not permit

         *         null values, and the specified value is null

         * @throws IllegalArgumentException if some property of this value

         *         prevents it from being stored in the backing map

         * @throws IllegalStateException implementations may, but are not

         *         required to, throw this exception if the entry has been

         *         removed from the backing map.

         */

        V setValue(V value);

 

        /**

         * Compares the specified object with this entry for equality.

         * Returns <tt>true</tt> if the given object is also a map entry and

         * the two entries represent the same mapping.  More formally, two

         * entries <tt>e1</tt> and <tt>e2</tt> represent the same mapping

         * if<pre>

         *     (e1.getKey()==null ?

         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &amp;&amp;

         *     (e1.getValue()==null ?

         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))

         * </pre>

         * This ensures that the <tt>equals</tt> method works properly across

         * different implementations of the <tt>Map.Entry</tt> interface.

         *

         * @param o object to be compared for equality with this map entry

         * @return <tt>true</tt> if the specified object is equal to this map

         *         entry

         */

        boolean equals(Object o);

 

        /**

         * Returns the hash code value for this map entry.  The hash code

         * of a map entry <tt>e</tt> is defined to be: <pre>

         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^

         *     (e.getValue()==null ? 0 : e.getValue().hashCode())

         * </pre>

         * This ensures that <tt>e1.equals(e2)</tt> implies that

         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries

         * <tt>e1</tt> and <tt>e2</tt>, as required by the general

         * contract of <tt>Object.hashCode</tt>.

         *

         * @return the hash code value for this map entry

         * @see Object#hashCode()

         * @see Object#equals(Object)

         * @see #equals(Object)

         */

        int hashCode();

 

        /**

         * Returns a comparator that compares {@link Map.Entry} in natural order on key.

         *

         * <p>The returned comparator is serializable and throws {@link

         * NullPointerException} when comparing an entry with a null key.

         *

         * @param  <K> the {@link Comparable} type of then map keys

         * @param  <V> the type of the map values

         * @return a comparator that compares {@link Map.Entry} in natural order on key.

         * @see Comparable

         * @since 1.8

         */

        public static <K extends Comparable<? super K>, V> Comparator<Map.Entry<K,V>> comparingByKey() {

            return (Comparator<Map.Entry<K, V>> & Serializable)

                (c1, c2) -> c1.getKey().compareTo(c2.getKey());

        }

 

        /**

         * Returns a comparator that compares {@link Map.Entry} in natural order on value.

         *

         * <p>The returned comparator is serializable and throws {@link

         * NullPointerException} when comparing an entry with null values.

         *

         * @param <K> the type of the map keys

         * @param <V> the {@link Comparable} type of the map values

         * @return a comparator that compares {@link Map.Entry} in natural order on value.

         * @see Comparable

         * @since 1.8

         */

        public static <K, V extends Comparable<? super V>> Comparator<Map.Entry<K,V>> comparingByValue() {

            return (Comparator<Map.Entry<K, V>> & Serializable)

                (c1, c2) -> c1.getValue().compareTo(c2.getValue());

        }

 

        /**

         * Returns a comparator that compares {@link Map.Entry} by key using the given

         * {@link Comparator}.

         *

         * <p>The returned comparator is serializable if the specified comparator

         * is also serializable.

         *

         * @param  <K> the type of the map keys

         * @param  <V> the type of the map values

         * @param  cmp the key {@link Comparator}

         * @return a comparator that compares {@link Map.Entry} by the key.

         * @since 1.8

         */

        public static <K, V> Comparator<Map.Entry<K, V>> comparingByKey(Comparator<? super K> cmp) {

            Objects.requireNonNull(cmp);

            return (Comparator<Map.Entry<K, V>> & Serializable)

                (c1, c2) -> cmp.compare(c1.getKey(), c2.getKey());

        }

 

        /**

         * Returns a comparator that compares {@link Map.Entry} by value using the given

         * {@link Comparator}.

         *

         * <p>The returned comparator is serializable if the specified comparator

         * is also serializable.

         *

         * @param  <K> the type of the map keys

         * @param  <V> the type of the map values

         * @param  cmp the value {@link Comparator}

         * @return a comparator that compares {@link Map.Entry} by the value.

         * @since 1.8

         */

        public static <K, V> Comparator<Map.Entry<K, V>> comparingByValue(Comparator<? super V> cmp) {

            Objects.requireNonNull(cmp);

            return (Comparator<Map.Entry<K, V>> & Serializable)

                (c1, c2) -> cmp.compare(c1.getValue(), c2.getValue());

        }

    }

© 著作权归作者所有

共有 人打赏支持
writeademo
粉丝 23
博文 516
码字总数 188548
作品 0
东城
System.setProperty 与 System.getProperty

System可以有对标准输入,标准输出,错误输出流;对外部定义的属性和环境变量的访问;加载文件和库的方法;还有快速复制数组的一部分的实用方法。 System.getProperties()可以确定当前的系统...

Shawn_Cheung
2014/05/26
0
0
Get System Info

Ch15 系统程序设计 1 System 1.1 I/O流  public static InputStream in: 读取字符的标准输入流。  public static PrintStream out: 标准输出流。  public static PrintStream err: 标准......

长平狐
2012/09/03
52
0
Java 判断操作系统类型(适用于各种操作系统)

最近一段时间写一个授权的程序,需要获取很多信息来保证程序不能随意复制使用,必须经过授权才可以。 为了限制用户使用的操作系统,必须有统一的方法来获取才可以。 在JAVA中,通过System.ge...

zh119893
2014/06/30
376
0
java 获取系统信息(从lucene源码找的)

/ The value of <tt>System.getProperty("java.version")<tt>. / public static final String JAVA_VERSION = System.getProperty("java.version"); /** True iff this is Java version 1.1.......

jiangtao
2012/01/30
0
0
介绍一些clojure中的关键字

想更多的人进来泰伦clojure clojure是一个很优秀的语言 正题= = 首先是打印输出用到的 pr prn print println 合并字符串 str 如果木有参数则返回一个空字符串,如果有一个对象则返回.toString...

Loli控
2011/09/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

arts-week10

Algorithm 905. Sort Array By Parity - LeetCode Review Who’s Afraid of the Big Bad Preloader? 一文读懂前端缓存 一个网络请求3个步骤:请求,处理,响应,而前端缓存主要在请求处响应这两步...

yysue
今天
4
0
00.编译OpenJDK-8u40的整个过程

前言 历经2天的折腾总算把OpenJDK给编译成功了,要说为啥搞这个,还得从面试说起,最近出去面试经常被问到JVM的相关东西,总感觉自己以前学的太浅薄,所以回来就打算深入学习,目标把《深入理...

凌晨一点
今天
5
0
python: 一些关于元组的碎碎念

初始化元组的时候,尤其是元组里面只有一个元素的时候,会出现一些很蛋疼的情况: def checkContentAndType(obj): print(obj) print(type(obj))if __name__=="__main__": tu...

Oh_really
昨天
6
2
jvm crash分析工具

介绍一款非常好用的jvm crash分析工具,当jvm挂掉时,会产生hs_err_pid.log。里面记录了jvm当时的运行状态以及错误信息,但是内容量比较庞大,不好分析。所以我们要借助工具来帮我们。 Cras...

xpbob
昨天
153
0
Qt编写自定义控件属性设计器

以前做.NET开发中,.NET直接就集成了属性设计器,VS不愧是宇宙第一IDE,你能够想到的都给你封装好了,用起来不要太爽!因为项目需要自从全面转Qt开发已经6年有余,在工业控制领域,有一些应用...

飞扬青云
昨天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部