oberlies
oberlies

Reputation: 11723

When a Java system property is set on the command line without value ("-Dkey"), what value does it get?

According to the Oracle documentation, I can set system properties of a Java process on the command line with the following syntax:

-Dproperty=value

But what happens when I don't specify the value, i.e. when I omit the "equals value" part:

-Dproperty

What value will the system property be set to? true? An empty string? Or any string with an undefined, implementation specific value?

Upvotes: 15

Views: 5334

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136062

It will return an empty string. According to System.getProperty(String key) null is returned only if there is no property with that key. So if we define a propety with -D it exists in the system

Upvotes: 10

oberlies
oberlies

Reputation: 11723

From simple trials with a Oracle HotSpot VM, I can see that system properties set on the command line without value get an empty string as value.

However this is only a partial answer to the question. A link to the some specification would be a better answer.

Upvotes: 4

Related Questions