Java System getProperties() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.System

Definition

In Java, System.getProperties() returns the entire set of system properties as a java.util.Properties object: the standard keys such as java.version and user.home, every -D option, and every key set by code.

It is the live object the JVM uses, not a copy. A later setProperty call shows up in it, and writing into it changes the system properties. Use it to list or search properties; for one key, getProperty is simpler.

A static method of the java.lang.System class, available since the first version of Java (JDK 1.0). Call it on the class name, as in System.getProperties(...). No import is needed, because classes in java.lang are always visible.

Syntax

No arguments; store the result in a Properties variable:

Java
Properties props = System.getProperties();
String home = props.getProperty("user.home");
Set<String> names = props.stringPropertyNames();  // all keys (a copy)
props.list(System.out);                           // dump everything (debugging)
CallWhat it does
System.getProperties()The live Properties object with all keys.
props.stringPropertyNames()A snapshot Set of all keys whose values are strings.
props.containsKey("java.version")Checks whether a key exists.
props.list(System.out)Prints every property; values are cut off after 40 characters.

Properties extends Hashtable, so its keys have no fixed order. Sort the names yourself, for example with a TreeSet, when the order matters.

Library declarations
Java
// java.lang.System
public static Properties getProperties()

Parameters

ParameterDescription
NonegetProperties() takes no parameters.

Return Value

Return ValueDescription
PropertiesThe current system properties. The same object is returned each time until setProperties replaces it.

Compare with Similar Methods

Reading many settings at once:

MethodHow it differs
getProperty(key)One value, with an optional default; the everyday choice.
getenv()All environment variables as a read-only Map.
new Properties() + load(reader)Your own settings from a .properties file, separate from system properties.

Java Examples

Example 1 — The Properties Object Is Live

Get the object once, then change a property through System.setProperty; the object sees the change.

Java
import java.util.Properties;

public class SystemGetPropertiesLive {
    public static void main(String[] args) {
        Properties props = System.getProperties();
        System.out.println("Has java.version: " + props.containsKey("java.version"));
        System.out.println("app.mode before: " + props.getProperty("app.mode"));

        System.setProperty("app.mode", "demo");
        System.out.println("app.mode after: " + props.getProperty("app.mode"));
        System.out.println("Same object each call: " + (props == System.getProperties()));
    }
}

How It Works

  1. All keys in one object. containsKey("java.version") is true because every JVM defines that standard key at startup.
  2. Not a snapshot. props was fetched before "app.mode" existed, yet after System.setProperty it returns "demo": both work on the same object.
  3. One shared instance. A second getProperties() call returns the very same object, so == is true.

Example 2 — List Your Own Keys in Sorted Order

Collect the keys that start with "shop." into a TreeSet, which keeps them sorted, then print each key and value.

Java
import java.util.Properties;
import java.util.TreeSet;

public class SystemGetPropertiesPrefix {
    public static void main(String[] args) {
        System.setProperty("shop.name", "Corner Store");
        System.setProperty("shop.currency", "EUR");
        System.setProperty("shop.open", "09:00");

        Properties props = System.getProperties();
        TreeSet<String> names = new TreeSet<>();
        for (String name : props.stringPropertyNames()) {
            if (name.startsWith("shop.")) {
                names.add(name);
            }
        }
        for (String name : names) {
            System.out.println(name + " = " + props.getProperty(name));
        }
        System.out.println("More than 3 properties in total? " + (props.size() > 3));
    }
}

How It Works

  1. A safe copy of the keys. stringPropertyNames() returns a new set of all keys, including the dozens of standard ones, that is not affected by later changes.
  2. Filter and sort. Only names starting with "shop." go into the TreeSet, which orders them alphabetically: currency, name, open. A plain loop over props would have no fixed order.
  3. Many more keys. Besides the three shop keys, the standard properties are in the same object, so props.size() > 3 is true.

Example 3 — Check the Keys Every JVM Must Provide

The documentation lists properties that are always present. The program counts how many of them it finds, without printing any values.

Java
import java.util.Properties;

public class SystemGetPropertiesKeys {
    public static void main(String[] args) {
        String[] keys = {"java.version", "java.vendor", "java.home", "os.name", "os.arch",
                "file.separator", "path.separator", "line.separator", "user.name", "user.home", "user.dir"};
        Properties props = System.getProperties();
        int found = 0;
        for (String key : keys) {
            if (props.getProperty(key) != null) {
                found++;
            }
        }
        System.out.println("Standard keys checked: " + keys.length);
        System.out.println("Standard keys found: " + found);
        System.out.println("Made-up key found: " + props.containsKey("codetofun.not.a.key"));
    }
}

How It Works

  1. A checklist. The array holds 11 of the keys that the getProperties documentation promises, covering Java, the operating system, separators, and the user.
  2. All present. Every one of them has a value on every JVM, so all 11 are found; the values themselves stay unprinted because they differ per machine.
  3. Unknown keys are simply absent. containsKey returns false for a name nobody defined, without throwing.

Frequently Asked Questions

A java.util.Properties object containing every system property: the standard ones, -D options, and keys set by your code.
No. It returns the live object the JVM uses, so later setProperty calls are visible in it and changes to it affect getProperty.
Call System.getProperties().list(System.out), or loop over stringPropertyNames(), sorted with a TreeSet, and print each key with getProperty.
Properties is a kind of Hashtable, which does not keep keys in order. Sort the key names first if you need a stable order.
java.version, java.vendor, java.vendor.url, java.home, java.class.version, java.class.path, os.name, os.arch, os.version, file.separator, path.separator, line.separator, user.name, user.home, and user.dir, among others.

Next: getProperty()

Read one system property, optionally with a default value.

getProperty() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful