首页 > 其他分享 >System.getProperty方法

System.getProperty方法

时间:2022-09-01 01:33:15浏览次数:53  
标签:Java java specification System vendor version key getProperty 方法

Demo

private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
private static String zookeeperPort = System.getProperty("zookeeper.port", "2181");

使用System.getProperty获得属性,如果未获得指定key的值,使用后面的作为default value。

 

System.getProperty方法支持以下属性:

  • java.version:Java Runtime Environment version, which may be interpreted as a Runtime.Version
  • java.version.date:Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD format, which may be interpreted as a java.time.LocalDate
  • java.vendor:Java Runtime Environment vendor
  • java.vendor.url:Java vendor URL
  • java.vendor.version:Java vendor version
  • java.home:Java installation directory
  • java.vm.specification.version:Java Virtual Machine specification version, whose value is the feature element of the runtime version
  • java.vm.specification.vendor:Java Virtual Machine specification vendor
  • java.vm.specification.name:Java Virtual Machine specification name
  • java.vm.version:Java Virtual Machine implementation version which may be interpreted as a Runtime.Version
  • java.vm.vendor:Java Virtual Machine implementation vendor
  • java.vm.name:Java Virtual Machine implementation name
  • java.specification.version:Java Runtime Environment specification version, whose value is the feature element of the runtime version
  • java.specification.vendor:Java Runtime Environment specification vendor
  • java.specification.name:Java Runtime Environment specification name
  • java.class.version:Java class format version number
  • java.class.path:Java class path (refer to ClassLoader.getSystemClassLoader() for details)
  • java.library.path:List of paths to search when loading libraries
  • java.io.tmpdir:Default temp file path
  • java.compiler:Name of JIT compiler to use
  • os.name:Operating system name
  • os.arch:Operating system architecture
  • os.version:Operating system version
  • file.separator:File separator ("/" on UNIX)
  • path.separator:Path separator (":" on UNIX)
  • line.separator:Line separator ("\n" on UNIX)
  • user.name:User's account name
  • user.home:User's home directory
  • user.dir:User's current working directory
    public static String getProperty(String key) {
        checkKey(key);
        SecurityManager sm = getSecurityManager();
        if (sm != null) {
            sm.checkPropertyAccess(key);
        }

        return props.getProperty(key);
    }

  

 checkKey(String key)

private static void checkKey(String key) {
        if (key == null) {
            throw new NullPointerException("key can't be null");
        }
        if (key.equals("")) {
            throw new IllegalArgumentException("key can't be empty");
        }
    }
props.getProperty(key)
    public String getProperty(String key) {
        Object oval = map.get(key);
        String sval = (oval instanceof String) ? (String)oval : null;
        Properties defaults;
        return ((sval == null) && ((defaults = this.defaults) != null)) ? defaults.getProperty(key) : sval;
    }

 

标签:Java,java,specification,System,vendor,version,key,getProperty,方法
From: https://www.cnblogs.com/use-D/p/16645121.html

相关文章

  • 高级开发人员知识:JavaScript 数组方法第 3 部分
    高级开发人员知识:JavaScript数组方法第3部分今天让我们来点高级的。这些数组方法总是遍历数组。基本上,您可以通过基本的for循环获得相同的功能。如果是这样,我们为什......
  • 在 Nodejs 中从终端获取用户输入的 4 种方法。
    在Nodejs中从终端获取用户输入的4种方法。当我们开始学习任何编程语言时,我们希望从终端获取用户输入。大多数人从c、c++、java等语言开始他们的编程之旅。在这些语......
  • jdk8新特性之方法引用和日期
    方法引用的三种表现形式方法引用的基本思想是,如果一个Lambda代表的只是“直接调用这个方法”,那最好还是用名称来调用它,而不是去描述如何调用它。事实上,方法引用就是让你......
  • 静态文件、请求方法、request对象、连接数据库、ORM
    目录静态文件及相关配置一、编写登录功能二、访问资源三、静态文件1.定义:2.位置:3.static文件夹:4.针对静态文件资源的访问也需要提前开设相应的接口5.接口前缀6.动态解析请......
  • request对象方法与django连接MySQL
    静态文件配置1.编写一个登录功能1.1创建django项目并创建一个app1.2在urls.py添加一组对应关系urlpatterns=[path('admin/',admin.site.urls),path('log......
  • CentOS yum 段错误 (core dumped)解决方法
    CentOSyum段错误(coredumped)解决方法_RedHat/Centos_操作系统_脚本之家 https://www.jb51.net/os/RedHat/208481.html今天在yuminstall或者yumupdate的时候都提......
  • Python根据类中属性自定义排序的方法
    如果以创建的对象作为列表中的元素,那么对列表进行排序时可使用sort()函数或sorted()函数,但要注意的是:①当排序对象为列表的时候两者适合的场景不同②sorted()函数会返......
  • 方法递归调用
    1.简单地说,递归就是方法自己调用自己,每次调用时传入不同的变量,递归有助于变成这解决复杂问题,同时可以让代码变得简洁。2.recursion 递归3.    4.factorial......
  • Java中“接口”可以作为方法的返回值吗?
    可以返回接口,接口虽然不能被实例化,但是接口的实现类都可以向上转型为接口。所谓面向接口编程是指我们在编写代码时对数据参数的定义尽量写成接口,待真正实现的时候再用实际......
  • 关于BeanUtils.populate()方法的疑问?
    前几天的在写前端register.jsp的时候,发现前端需要封装的对象好多,网上查了下,竟然可以用BeanUtils来封装,于是在RegistUserServlet中用了BeanUtils来封装成user对象。......