java System.getProperty()参数大全

本文详细介绍了使用Java的System.getProperty()方法获取系统属性的参数及其含义。涵盖了Java运行时环境、虚拟机、操作系统及用户相关的核心配置信息。

java System.getProperty()参数大全java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification 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
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification 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
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
java.ext.dirs Path of extension directory or directories
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

中文对照:

java.version Java 运行时环境版本

java.vendor Java 运行时环境供应商

java.vendor.url Java 供应商的 URL

java.home Java 安装目录

java.vm.specification.version Java 虚拟机规范版本

java.vm.specification.vendor Java 虚拟机规范供应商

java.vm.specification.name Java 虚拟机规范名称

java.vm.version Java 虚拟机实现版本
java.vm.vendor Java 虚拟机实现供应商

java.vm.name Java 虚拟机实现名称

java.specification.version Java 运行时环境规范版本

java.specification.vendor Java 运行时环境规范供应商

java.specification.name Java 运行时环境规范名称

java.class.version Java 类格式版本号

java.class.path Java 类路径

java.library.path 加载库时搜索的路径列表

java.io.tmpdir 默认的临时文件路径

java.compiler 要使用的 JIT 编译器的名称

java.ext.dirs 一个或多个扩展目录的路径

os.name 操作系统的名称

os.arch 操作系统的架构

os.version 操作系统的版本

file.separator 文件分隔符(在 UNIX 系统中是“/”)

path.separator 路径分隔符(在 UNIX 系统中是“:”)

line.separator 行分隔符(在 UNIX 系统中是“/n”)

user.name 用户的账户名称

user.home 用户的主目录

user.dir 用户的当前工作目录

代码:

public static void main(String[] args) {
System.out.println(“java.version:” + System.getProperty(“java.version”));
System.out.println(“java.vendor:” + System.getProperty(“java.vendor”));
System.out.println(“java.vendor.url:” + System.getProperty(“java.vendor.url”));
System.out.println(“java.home:” + System.getProperty(“java.home”));
System.out.println(“java.vm.specification.version:” + System.getProperty(“java.vm.specification.version”));
System.out.println(“java.vm.specification.vendor:” + System.getProperty(“java.vm.specification.vendor”));
System.out.println(“java.vm.specification.name:” + System.getProperty(“java.vm.specification.name”));
System.out.println(“java.vm.version:” + System.getProperty(“java.vm.version”));
System.out.println(“java.vm.vendor:” + System.getProperty(“java.vm.vendor”));
System.out.println(“java.vm.name:” + System.getProperty(“java.vm.name”));
System.out.println(“java.specification.version:” + System.getProperty(“java.specification.version”));
System.out.println(“java.specification.vendor:” + System.getProperty(“java.specification.vendor”));
System.out.println(“java.specification.name:” + System.getProperty(“java.specification.name”));
System.out.println(“java.class.version:” + System.getProperty(“java.class.version”));
System.out.println(“java.class.path:” + System.getProperty(“java.class.path”));
System.out.println(“java.library.path:” + System.getProperty(“java.library.path”));
System.out.println(“java.io.tmpdir:” + System.getProperty(“java.io.tmpdir”));
System.out.println(“java.compiler:” + System.getProperty(“java.compiler”));
System.out.println(“java.ext.dirs:” + System.getProperty(“java.ext.dirs”));
System.out.println(“os.name:” + System.getProperty(“os.name”));
System.out.println(“os.arch:” + System.getProperty(“os.arch”));
System.out.println(“os.version:” + System.getProperty(“os.version”));
System.out.println(“file.separator:” + System.getProperty(“file.separator”));
System.out.println(“line.separator:” + System.getProperty(“line.separator”));
System.out.println(“user.name:” + System.getProperty(“user.name”));
System.out.println(“user.home:” + System.getProperty(“user.home”));
System.out.println(“user.dir:” + System.getProperty(“user.dir”));
}

运行结果:

java.version:1.6.0_02
java.vendor:Sun Microsystems Inc.
java.vendor.url:http://java.sun.com/
java.home:D:\Program Files\Java\jdk1.6.0_02\jre
java.vm.specification.version:1.0
java.vm.specification.vendor:Sun Microsystems Inc.
java.vm.specification.name:Java Virtual Machine Specification
java.vm.version:1.6.0_02-b06
java.vm.vendor:Sun Microsystems Inc.
java.vm.name:Java HotSpot(TM) Client VM
java.specification.version:1.6
java.specification.vendor:Sun Microsystems Inc.
java.specification.name:Java Platform API Specification
java.class.version:50.0
java.class.path:E:\workspace\test\WebRoot\WEB-INF\classes;E:\workspace\test\WebRoot\WEB-INF\lib\activation.jar;

java.library.path:D:\Program Files\Java\jdk1.6.0_02\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;D:\Program Files\Java\jdk1.6.0_02\bin;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\SinoVoice\jTTS 5.0 Desktop\Bin;E:\J2EE\plugins\ant\apache-ant-1.7.1\bin;C:\Program Files\CVSNT;C:\Program Files\StormII\Codec;C:\Program Files\StormII
java.io.tmpdir:C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
java.compiler:null
java.ext.dirs:D:\Program Files\Java\jdk1.6.0_02\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
os.name:Windows 2003
os.arch:x86
os.version:5.2
file.separator:\
line.separator:

user.name:Administrator
user.home:C:\Documents and Settings\Administrator
user.dir:E:\workspace\mvnforum

System.getProperty() 方法是 Java 中获取系统属性的重要途径之一,它为获取系统相关的信息提供了方便快捷的方式,通过合理运用该方法,能更好地了解和控制 Java 程序的运行环境,实现更灵活、更健壮的应用程序开发[^1]。 使用方法方面,System.getProperty() 方法有两种重载形式: - `String getProperty(String key)`:该方法接收一个字符串类型的参数 `key`,用于指定要获取的系统属性的名称。如果指定名称的属性存在,则返回该属性的值;如果不存在,则返回 `null`。 - `String getProperty(String key, String def)`:该方法同样接收一个字符串类型的参数 `key` 用于指定要获取的系统属性的名称,另外还接收一个默认值 `def`。如果指定名称的属性存在,则返回该属性的值;如果不存在,则返回默认值 `def`。 作用上,System.getProperty() 方法可用于获取系统的各种属性,如 Java 运行时环境版本、Java 安装目录、操作系统名称、用户的主目录等。这些信息有助于开发者根据不同的系统环境来调整程序的行为。 以下是使用 System.getProperty() 方法的示例代码: ```java public class SystemPropertyExample { public static void main(String[] args) { // 获取 Java 运行时环境版本 String javaVersion = System.getProperty("java.version"); System.out.println("Java Version: " + javaVersion); // 获取 Java 安装目录 String javaHome = System.getProperty("java.home"); System.out.println("Java Home: " + javaHome); // 获取操作系统名称 String osName = System.getProperty("os.name"); System.out.println("OS Name: " + osName); // 获取用户的主目录 String userHome = System.getProperty("user.home"); System.out.println("User Home: " + userHome); // 获取不存在的属性,返回 null String nonExistentProperty = System.getProperty("non.existent.property"); System.out.println("Non-existent Property: " + nonExistentProperty); // 获取不存在的属性,返回默认值 String nonExistentPropertyWithDefault = System.getProperty("non.existent.property", "default value"); System.out.println("Non-existent Property with Default: " + nonExistentPropertyWithDefault); } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值