System.getProperty("os.name")这里的key对应的value是哪里取值呢?
System.getProperty("os.name")这里的key对应的value是哪里取值呢?
writeademo 发表于11个月前
System.getProperty("os.name")这里的key对应的value是哪里取值呢?
  • 发表于 11个月前
  • 阅读 34
  • 收藏 1
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

 

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());

        }

    }

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 17
博文 396
码字总数 160385
×
writeademo
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: