← Recipes

Stable Runtime Defaults

Pin process-wide defaults that otherwise depend on host configuration.

Flags

-Dfile.encoding-Duser.timezone-Duser.language-Duser.country

-D options set system properties before application code starts. Encoding, timezone, and locale affect logs, parsing, formatting, tests, serialized data, and integrations.

Option details

-Dfile.encoding=UTF-8
Sets the default charset used by APIs that rely on the process default. Prefer explicit charsets in code, but this avoids host-dependent surprises.
-Duser.timezone=UTC
Sets the default JVM timezone. This keeps timestamps, scheduled calculations, and log formatting stable across hosts.
-Duser.language=en
Sets the default language part of the JVM locale.
-Duser.country=US
Sets the default country part of the JVM locale. Together with language, it affects formatting, parsing, collation, and localized messages.

When to use it

Use this for services, batch jobs, CI tests, and data pipelines that must behave the same across laptops, containers, and servers.

Java version support

-D system properties apply across all Java versions. Java 18 made UTF-8 the default charset, but setting -Dfile.encoding=UTF-8 can still document intent and stabilize older runtimes. Locale and timezone properties remain useful across releases.

Related JEPs

Examples

java -Dfile.encoding=UTF-8 -Duser.timezone=UTC \
  -Duser.language=en -Duser.country=US \
  -jar app.jar

Use this in services and batch jobs that exchange data across machines or regions.

Verify

Log Charset.defaultCharset(), ZoneId.systemDefault(), and Locale.getDefault() during startup.