Java program Query System Parameters

Source: Internet
Author: User

Java program Query System Parameters

System parameters are the parameters set in the system, such as the system name and JVM version. Java programs can be executed across platforms. The values of these system parameters can be used to determine the current execution environment. Then, the program can be executed based on the features of different platforms, make the best adjustments dynamically. The following code retrieves system parameters.

package test;import java.util.Enumeration;import java.util.Properties;public class Test {public static void main(String args[]){Properties p = System.getProperties();Enumeration enume = p.propertyNames();String propertyName = "";String property = "";while( enume.hasMoreElements()){propertyName = (String)enume.nextElement();property = p.getProperty(propertyName);System.out.println("Property "+ propertyName +"' = '"+property+"'");}}}

The running result is:

Property java.runtime.name' = 'Java(TM) SE Runtime Environment'Property sun.boot.library.path' = 'C:\Program Files\Java\jre7\bin'Property java.vm.version' = '23.25-b01'Property java.vm.vendor' = 'Oracle Corporation'Property java.vendor.url' = 'http://java.oracle.com/'Property path.separator' = ';'Property java.vm.name' = 'Java HotSpot(TM) Client VM'Property file.encoding.pkg' = 'sun.io'Property user.script' = ''Property user.country' = 'CN'Property sun.java.launcher' = 'SUN_STANDARD'Property sun.os.patch.level' = 'Service Pack 1'Property java.vm.specification.name' = 'Java Virtual Machine Specification'Property user.dir' = 'C:\Users\Administrator\workspace\Test'Property java.runtime.version' = '1.7.0_25-b17'Property java.awt.graphicsenv' = 'sun.awt.Win32GraphicsEnvironment'Property java.endorsed.dirs' = 'C:\Program Files\Java\jre7\lib\endorsed'Property os.arch' = 'x86'Property java.io.tmpdir' = 'C:\Users\ADMINI~1\AppData\Local\Temp\'Property line.separator' = ''Property java.vm.specification.vendor' = 'Oracle Corporation'Property user.variant' = ''Property os.name' = 'Windows 7'Property sun.jnu.encoding' = 'GBK'Property java.library.path' = 'C:\Program Files\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;D:\app\Administrator\product\11.2.0\dbhome_1\bin;C:\Program Files\Java\jdk1.7.0_25;D:\Program Files\Java\jdk1.6.0_27;\bin;C:\Program Files\Java\jdk1.7.0_25;D:\Program Files\Java\jdk1.6.0_27;\jre\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;D:\Program Files\TortoiseSVN\bin;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_27;\bin;D:\Program Files\Java\jdk1.6.0_27;\jre\bin;d:\Program Files\Windows7Master;D:\Program Files\MySQL\MySQL Utilities 1.3.4\;D:\Program Files\MATLAB\R2010b\runtime\win32;D:\Program Files\MATLAB\R2010b\bin;C:\Program Files\jEdit;D:\eclipse;;.'Property java.specification.name' = 'Java Platform API Specification'Property java.class.version' = '51.0'Property sun.management.compiler' = 'HotSpot Client Compiler'Property os.version' = '6.1'Property user.home' = 'C:\Users\Administrator'Property user.timezone' = ''Property java.awt.printerjob' = 'sun.awt.windows.WPrinterJob'Property file.encoding' = 'GBK'Property java.specification.version' = '1.7'Property user.name' = 'Administrator'Property java.class.path' = 'C:\Users\Administrator\workspace\Test\bin'Property java.vm.specification.version' = '1.7'Property sun.arch.data.model' = '32'Property java.home' = 'C:\Program Files\Java\jre7'Property sun.java.command' = 'test.Test'Property java.specification.vendor' = 'Oracle Corporation'Property user.language' = 'zh'Property awt.toolkit' = 'sun.awt.windows.WToolkit'Property java.vm.info' = 'mixed mode, sharing'Property java.version' = '1.7.0_25'Property java.ext.dirs' = 'C:\Program Files\Java\jre7\lib\ext;C:\windows\Sun\Java\lib\ext'Property sun.boot.class.path' = 'C:\Program Files\Java\jre7\lib\resources.jar;C:\Program Files\Java\jre7\lib\rt.jar;C:\Program Files\Java\jre7\lib\sunrsasign.jar;C:\Program Files\Java\jre7\lib\jsse.jar;C:\Program Files\Java\jre7\lib\jce.jar;C:\Program Files\Java\jre7\lib\charsets.jar;C:\Program Files\Java\jre7\lib\jfr.jar;C:\Program Files\Java\jre7\classes'Property java.vendor' = 'Oracle Corporation'Property file.separator' = '\'Property java.vendor.url.bug' = 'http://bugreport.sun.com/bugreport/'Property sun.cpu.endian' = 'little'Property sun.io.unicode.encoding' = 'UnicodeLittle'Property sun.desktop' = 'windows'Property sun.cpu.isalist' = 'pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86'
Of course, the results of different platforms will be different.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.