zoukankan      html  css  js  c++  java
  • where both the key and the value are strings

    Environment Variables (The Java™ Tutorials > Essential Classes > The Platform Environment) https://docs.oracle.com/javase/tutorial/essential/environment/env.html

    Environment Variables

    Many operating systems use environment variables to pass configuration information to applications. Like properties in the Java platform, environment variables are key/value pairs, where both the key and the value are strings. The conventions for setting and using environment variables vary between operating systems, and also between command line interpreters. To learn how to pass environment variables to applications on your system, refer to your system documentation.

    Querying Environment Variables

    On the Java platform, an application uses System.getenv to retrieve environment variable values. Without an argument, getenv returns a read-only instance of java.util.Map, where the map keys are the environment variable names, and the map values are the environment variable values. This is demonstrated in the EnvMap example:

    import java.util.Map;
    
    public class EnvMap {
        public static void main (String[] args) {
            Map<String, String> env = System.getenv();
            for (String envName : env.keySet()) {
                System.out.format("%s=%s%n",
                                  envName,
                                  env.get(envName));
            }
        }
    }
    
    

    With a String argument, getenv returns the value of the specified variable. If the variable is not defined, getenv returns null. The Env example uses getenv this way to query specific environment variables, specified on the command line:

    public class Env {
        public static void main (String[] args) {
            for (String env: args) {
                String value = System.getenv(env);
                if (value != null) {
                    System.out.format("%s=%s%n",
                                      env, value);
                } else {
                    System.out.format("%s is"
                        + " not assigned.%n", env);
                }
            }
        }
    }
    
    

    Passing Environment Variables to New Processes

    When a Java application uses a ProcessBuilder object to create a new process, the default set of environment variables passed to the new process is the same set provided to the application's virtual machine process. The application can change this set using ProcessBuilder.environment.

    Platform Dependency Issues

    There are many subtle differences between the way environment variables are implemented on different systems. For example, Windows ignores case in environment variable names, while UNIX does not. The way environment variables are used also varies. For example, Windows provides the user name in an environment variable called USERNAME, while UNIX implementations might provide the user name in USERLOGNAME, or both.

    To maximize portability, never refer to an environment variable when the same value is available in a system property. For example, if the operating system provides a user name, it will always be available in the system property user.name.

  • 相关阅读:
    剑指Offer_栈的压入序列是否有对应的弹出序列
    剑指Offer_Java_顺时针打印矩阵(二维数组)
    排序算法Java代码实现(四)—— 归并排序
    排序算法Java代码实现(六)—— 堆排序
    排序算法Java代码实现(五)—— 快速排序
    排序算法Java代码实现(三)—— 插入排序 和 希尔排序
    CSS sprites
    局部变量和参数传递的问题
    隐藏元素的方式有哪些
    box-sizing属性的的用法
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9965414.html
Copyright © 2011-2022 走看看