Java System Properties
Quick Reference Guide Java System Property

The java system property is used to define DNS host name address resolution to the InetAddress class

Default Value

Empty - By default, if the system property is not defined Java will use the default address resolution.

Overview of

The system property specifies a file system path to a file that provides DNS name resolution to the InetAddress methods getByAddress or getByName. The format of this file is the same as a /etc/hosts file, here's an example:

# comment   localhost

If the system property points to a file path that does not exist, all DNS resolutions will fail with an UnknownHostException.

Other Networking System Properties

Here are some other networking Java system properties:

Supported Since

Java has supported the system property since Java 9.

Setting on Startup

You can set the java system property during startup of the java runtime using the -D command line argument:

java MyAppMain

You may also be able to specify via the JAVA_TOOL_OPTIONS environment variable:

Setting / Reading at Runtime

You can set at runtime with the following Java code:

System.setProperty("", "/path/to/hosts");

WARNING: Depending on the property and JVM version using setProperty may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the system property may be cached within an internal private static variable of the implementing class.

To read the value of at runtime, you can use this Java code:

String propertyValue = System.getProperty("");
if (propertyValue != null) {
    System.out.println(" = " + propertyValue);
} else {
    System.out.println(" was null");