目录
System.getProperties()可以确定当前的系统属性,返回值是一个Properties;
System.load(String filename)等同于:System.getProperties().load(String filename)它们的作用是可以从作为动态库的本地文件系统中以指定的文件名加载代码文件。
System.setProperties(Properties propes)将系统属性设置为Properties参数;
System.setProperties(String key,String value)等同于System.getProperties().setProperties(String key,String value):设置指定键指示的系统属性
- 键相关值的描述
- 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 用户的当前工作目录
Java代码
- public class TestSystemGetSet {
- static{
- System.setProperty("DB", "mysql");//可以作为全局变量,在任何地方使用
- }
- public static void main(String[] args) {
- System.out.println(System.getProperty("os.version"));
- System.out.println(System.getProperty("java.library.path"));
- System.out.println(System.getProperty("DB"));
-
- Properties properties = System.getProperties();
- for (Object key : properties.keySet()) {
- System.out.println("key=" + key + "\t\t\tvalue=" + properties.get(key));
- }
- }
- }
输出结果
- 10.0
- C:\Program Files\Java\jdk1.8.0_202\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;"C:\Program Files\Java\jdk1.8.0_202\bin;C:\Program Files\Java\jdk1.8.0_202\jre\bin;";C:\Program Files\Go\bin;C:\Program Files\Go\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\go\bin;C:\Program Files\JetBrains\GoLand 2023.2\bin;;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.3\bin;;.
- mysql
- key=java.runtime.name value=Java(TM) SE Runtime Environment
- key=sun.boot.library.path value=C:\Program Files\Java\jdk1.8.0_202\jre\bin
- key=java.vm.version value=25.202-b08
- key=DB value=mysql
- key=java.vm.vendor value=Oracle Corporation
- key=java.vendor.url value=http://java.oracle.com/
- key=path.separator value=;
- key=java.vm.name value=Java HotSpot(TM) 64-Bit Server VM
- key=file.encoding.pkg value=sun.io
- key=user.country value=CN
- key=user.script value=
- key=sun.java.launcher value=SUN_STANDARD
- key=sun.os.patch.level value=
- key=java.vm.specification.name value=Java Virtual Machine Specification
- key=user.dir value=D:\WorkSpace\EclipseWorkSpace\springboot_aop
- key=java.runtime.version value=1.8.0_202-b08
- key=java.awt.graphicsenv value=sun.awt.Win32GraphicsEnvironment
- key=java.endorsed.dirs value=C:\Program Files\Java\jdk1.8.0_202\jre\lib\endorsed
- key=os.arch value=amd64
- key=java.io.tmpdir value=C:\Users\ADMINI~1\AppData\Local\Temp\
- key=line.separator value=
-
- key=java.vm.specification.vendor value=Oracle Corporation
- key=user.variant value=
- key=os.name value=Windows 10
- key=sun.jnu.encoding value=GBK
- key=java.library.path value=C:\Program Files\Java\jdk1.8.0_202\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;"C:\Program Files\Java\jdk1.8.0_202\bin;C:\Program Files\Java\jdk1.8.0_202\jre\bin;";C:\Program Files\Go\bin;C:\Program Files\Go\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\Microsoft VS Code\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\go\bin;C:\Program Files\JetBrains\GoLand 2023.2\bin;;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.3\bin;;.
- key=java.specification.name value=Java Platform API Specification
- key=java.class.version value=52.0
- key=sun.management.compiler value=HotSpot 64-Bit Tiered Compilers
- key=os.version value=10.0
- key=user.home value=C:\Users\Administrator
- key=user.timezone value=
- key=java.awt.printerjob value=sun.awt.windows.WPrinterJob
- key=file.encoding value=UTF-8
- key=java.specification.version value=1.8
- key=java.class.path value=C:\Program Files\Java\jdk1.8.0_202\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\rt.jar;D:\WorkSpace\EclipseWorkSpace\springboot_aop\target\test-classes;D:\WorkSpace\EclipseWorkSpace\springboot_aop\target\classes;D:\.m2\repo\org\springframework\spring-context\5.1.6.RELEASE\spring-context-5.1.6.RELEASE.jar;D:\.m2\repo\org\springframework\spring-aop\5.1.6.RELEASE\spring-aop-5.1.6.RELEASE.jar;D:\.m2\repo\org\springframework\spring-beans\5.1.6.RELEASE\spring-beans-5.1.6.RELEASE.jar;D:\.m2\repo\org\springframework\spring-core\5.1.6.RELEASE\spring-core-5.1.6.RELEASE.jar;D:\.m2\repo\org\springframework\spring-jcl\5.1.6.RELEASE\spring-jcl-5.1.6.RELEASE.jar;D:\.m2\repo\org\springframework\spring-expression\5.1.6.RELEASE\spring-expression-5.1.6.RELEASE.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.3\lib\idea_rt.jar
- key=user.name value=Administrator
- key=java.vm.specification.version value=1.8
- key=sun.java.command value=com.lwz.TestSystemGetSet
- key=java.home value=C:\Program Files\Java\jdk1.8.0_202\jre
- key=sun.arch.data.model value=64
- key=user.language value=zh
- key=java.specification.vendor value=Oracle Corporation
- key=awt.toolkit value=sun.awt.windows.WToolkit
- key=java.vm.info value=mixed mode
- key=java.version value=1.8.0_202
- key=java.ext.dirs value=C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
- key=sun.boot.class.path value=C:\Program Files\Java\jdk1.8.0_202\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_202\jre\classes
- key=java.vendor value=Oracle Corporation
- key=file.separator value=\
- key=java.vendor.url.bug value=http://bugreport.sun.com/bugreport/
- key=sun.io.unicode.encoding value=UnicodeLittle
- key=sun.cpu.endian value=little
- key=sun.desktop value=windows
- key=sun.cpu.isalist value=amd64
一个程序员最重要的能力是:写出高质量的代码!!
有道无术,术尚可求也,有术无道,止于术。
无论你是年轻还是年长,所有程序员都需要记住:时刻努力学习新技术,否则就会被时代抛弃!