Why couldn’t the architects of Java let us simply do:
java -jar -myProp="Hello World" myProgram.jar
It could work today but suppose that in next Java versions a -myProp argument is introduced as a JVM option.
How to distinguish your -myProp from the -myProp JVM option ? No way.
So it exists an obvious reason to use -D to define system properties.
As other example, instead of -myProp suppose you program relies on a -client system property.
It will not run :
java -jar -client="davidxxx" myProgram.jar
You would have a JVM error such as :
Unrecognized option: -client=davidxxx
as -client is a JVM standard option that expects no value.
But if you use -D-client, it is now fine as here -Dclient is defined as a system property that is distinct from the -client standard JVM option :
java -jar -D-client="davidxxx" myProgram.jar
Or by using both :
java -jar -client -D-client="davidxxx" myProgram.jar
To go further, not all JVM arguments start with -D. but most of them have a prefix (-D, -X, -XX) that allows in a someway to define namespaces.
You have distinct categories of JVM arguments :
1. Standard Options (-D but not only).
These are the most commonly used options that are supported by all implementations of the JVM.
You use -D to specify System properties but most of them don’t have any prefix :-verbose, -showversion, and so for…
2. Non-Standard Options (prefixed with -X)
These options are general purpose options that are specific to the Java HotSpot Virtual Machine.
For example : -Xmssize, -Xmxsize
3. Advanced Runtime Options (prefixed with -XX)
These options control the runtime behavior of the Java HotSpot VM.
4. Advanced JIT Compiler Options (prefixed with -XX)
These options control the dynamic just-in-time (JIT) compilation performed by the Java HotSpot VM.
5. Advanced Serviceability Options (prefixed with -XX)
These options provide the ability to gather system information and perform extensive debugging.
6. Advanced Garbage Collection Options (prefixed with -XX)
These options control how garbage collection (GC) is performed by the Java HotSpot VM.