Java System.getProperty method is very useful to find out the operating system information.

Java System.getProperty

java-system-getproperty

We can use System.getProperty() method to find out the Operating System information, user home directory, Java runtime version, path separator, line separator, user working directory, Java home, Java classpath, and various other useful information.

Java System getProperty Example

Java System class getProperties() method returns the Set of keys for the properties and here we will use it to list out all the system properties.

The output of the above System getProperty example program is;

Some of the valuable information being printed above are;

  1. The program is running on Mac OS, see output {os.name,Mac OS X}
  2. Java version is 1.8.0_131, see system property output {java.version,1.8.0_131}
  3. User name is pankaj, as seen in output {user.name,pankaj}
  4. Path separator is colon (:), see output {path.separator,:}
  5. It’s a 64-bit OS, see output {os.arch,x86_64}

There are many more useful information printed too, you should check them out.

We should use this System information where we need to make sure our program is platform independent, for example creating the file path we should use file.separator property and to read PATH information we should use path.separator variable. That’s all about System.getProperty in java.

By admin

Leave a Reply