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.
Code
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
Properties File ParserParse Java .properties files with comments, continuations, separators, and escapes, then emit clean JSON.Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.INI File ParserParse INI configuration files into nested JSON with section objects, global keys, and both semicolon and hash comment support.JSON to TOML ConverterTurn a JSON object into TOML, emitting nested objects as tables and arrays of objects as array-of-tables blocks.
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.
Report a problem with this exampleOpens a pre-filled issue on GitHub.