Using System.getProperty(String key) to retrieve system properties in Java

Description

The following code shows how to using System.getProperty(String key) to retrieve system properties.

This method returns the value of the specified property. It returns null if the specified property does not exist. Each property comes as a key/value pair.

There are system properties and user-defined properties. When a Java program runs, the JVM provides values that may be used by the program as properties.

For example, the os.name system property provides the name of the operating system running the JVM.

To get the value of the user.dir property, you use:

Example


//from ww  w .  j  a v a  2  s  . c o  m

  
public class Main{

  public static void main(String[] args){
    System.out.println(System.getProperty ("user.dir"));      
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization