In java -D what does the D stand for?

前端 未结 4 1614
陌清茗
陌清茗 2021-01-31 14:59

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

4条回答
  •  故里飘歌
    2021-01-31 15:51

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

    #include 
    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.

提交回复
热议问题