Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java -D what does the D stand for?

What does the D in

-Dproperty=value

Set a system property value.

Of the Java application launcher stand for? For some reason it's been bothering me, why D?

like image 425
septerr Avatar asked Sep 20 '12 18:09

septerr


4 Answers

I've always assumed it was to define the value of a property... possibly a legacy from C compilers, which often use -D as similar to #define in code.

EDIT: The closest I have to a source for this at the moment is some JDK 1.1 documentation which specifies the flag as:

Redefines a property value. propertyName is the name of the property whose value you want to change and newValue is the value to change it to. [...]

That at least contains the word "redefine" which is close to "define" :)

like image 102
Jon Skeet Avatar answered Nov 11 '22 14:11

Jon Skeet


In C/C++ compilers the similar syntax is used to define preprocessor macros from the command line:

#include <stdio.h>
int main(int argc, char* argv[]) {
    printf(GREETING);
    return 0;
}

.

gcc hello.c -DGREETING="\"Hello, world\""

Java doesn't have a preprocessor, but properties defined with -D are ofter used for the similar reason - to pass some program-specific information about the current environment. The only difference is that in Java we pass them in runtime, not in compile-time:

public class Hello {
    public static void main(String[] args) {
        System.out.println(System.getProperty("greeting"));
    }
}

.

java -Dgreeting="Hello, world" Hello

I think this similarity is the source of similar syntax.

like image 30
axtavt Avatar answered Nov 11 '22 13:11

axtavt


The reason is D stands for DEFINE, because what that command switch does is defining variables.

like image 44
Nelson Avatar answered Nov 11 '22 13:11

Nelson


It might be for Define, cause you are defining a property

like image 3
Shades88 Avatar answered Nov 11 '22 12:11

Shades88