Java

Source: Internet
Author: User
Tags java se

Only System. getProperties () can obtain system information. including the JDK path and system version. what I need is System. getProperty ("sun. desktop ") to obtain the system type. Because I use a Windows operating system, the returned String is windows. use System. getProperty ("OS. name ") to obtain more detailed information. The result is windows xp.

I recommend some fields that I think are useful.

User. home can be used to obtain the home directory of the current user.

Java. specification. version: get the current JDK version.

Java. class. path get classpath

User. name: get the current user name

Java. home get JDK path

Sun. OS. patch. level: get the system version number. It can also be said that the patch number is displayed as Service Pack 2.

User. dir main directory of the current program

OS. arch: displays the OS type as X86.

OS. version: displays the system Internal version.

Java. io. tmpdir displays the temporary directory of the current system

Later, it was found that the new features of Java SE 6.0 were much easier to judge the operating system type and then perform specific operations. because java. awt. java. awt. desktop. isDesktopSupported () can be used to obtain whether the current system supports java awt desktop extensions. obtain the Desktop of the current system if it is supported.

Java. awt. Desktop dp = java. awt. Desktop. getDesktop ();

Dp. browse (java.net. URI );

The default browser of the system can be started, so the cross-platform problem is solved. The following is the sample code:

Public class TestSystem {
Public static void main (String [] args ){
// Determine whether the current system supports Java AWT Desktop extension
If (java. awt. Desktop. isDesktopSupported ()){
Try {
// Create a URI instance
Java.net. URI uri = java.net. URI. create ("http://www.111cn.net /");
// Obtain the current system desktop extension
Java. awt. Desktop dp = java. awt. Desktop. getDesktop ();
// Determine whether the system Desktop supports the functions to be executed
If (dp. isSupported (java. awt. Desktop. Action. BROWSE )){
// Obtain the default browser link of the system.
Dp. browse (uri );
                }
} Catch (java. lang. NullPointerException e ){
// An exception is thrown when the uri is null.
} Catch (java. io. IOException e ){
// The default browser cannot be obtained.
            }            
        }
    }
}

Key-related value description
Java. version Java Runtime Environment version
Java. vendor Java Runtime Environment vendor
Java. vendor. url URL of the Java vendor
Java. home Java installation directory
Java. vm. specification. version Java virtual machine Standard 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 Standard version
Java. specification. vendor Java Runtime Environment specification vendor
Java. specification. name Java Runtime Environment Standard name
Java. class. version Java class format version number
Java. class. path Java class path
List of paths searched when the java. library. path library is loaded
Java. io. tmpdir default temporary file path
Name of the JIT compiler to be used by java. compiler
Java. ext. dirs: Path of one or more extension directories
OS. name of the operating system
OS. arch operating system architecture
OS. version
File. separator file delimiter ("/" in UNIX)
Path. separator path separator (":" In UNIX systems)
Line. separator line separator ("/n" in UNIX ")
User. name: account name of the user
User. home user's home directory
Current working directory of user. dir

Instance

Import java. util. Properties;

Properties props tutorial = System. getProperties (); // Obtain the System property set
String osName = props. getProperty ("OS. name"); // operating system name
String osArch = props. getProperty ("OS. arch"); // operating system architecture
String osVersion = props. getProperty ("OS. version"); // operating system version

String osName = System. getProperty ("OS. name"); // operating System name
String osArch = System. getProperty ("OS. arch"); // operating System architecture
String osVersion = System. getProperty ("OS. version"); // operating System version

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.