System Properties Read Set And Defaults

Read built-in properties, supply defaults for absent keys, and mutate values at runtime — unlike environment variables, properties are writable.

JavaConfig Management

Code

snippet
public class PropertyProbe {

    public static void main(String[] args) {
        // built-in properties: JDK version, working directory, temp directory
        System.out.println("java.version   = " + System.getProperty("java.version"));
        System.out.println("user.dir       = " + System.getProperty("user.dir"));
        System.out.println("java.io.tmpdir = " + System.getProperty("java.io.tmpdir"));

        // reads with a default: a missing key yields the fallback instead of null
        System.out.println("stage = " + System.getProperty("app.stage", "unset"));

        // writing and clearing at runtime: the effect equals launching with -Dapp.stage=prod
        System.setProperty("app.stage", "prod");
        System.out.println("stage now = " + System.getProperty("app.stage"));
        System.clearProperty("app.stage");
        System.out.println("stage cleared = " + System.getProperty("app.stage", "unset"));
    }
}

How it works

Count the class PropertyProbe and the function main as the entire surface area of System Properties Read Set And Defaults.

Putting it to use

Each run prints the 6 labeled blocks java.version =, user.dir =, java.io.tmpdir =, stage =, stage now =, stage cleared = in source order.

Core lines

System.setProperty("app.stage", "prod");
System.clearProperty("app.stage");

Interactive Tools for This Topic

FAQ

What does System Properties Read Set And Defaults print when run?
Invoke the file as-is — the `java.version =`, `user.dir =`, `java.io.tmpdir =` prefixes identify which step printed each line.