Java – different methods of passing parameters: String args [] or – D?

I've seen many Java use the - D option to pass some parameters

The more familiar method is to pass the parameter with string [] args to the main method

So what is the difference between the two methods?

Add 1

Is there a situation where we have to prefer one to another?

Solution

-The D switch is used to set system properties instead of passing parameters to the program In fact, the two methods don't even send information to the same place: the string [] parameter is sent to your program, and the switch is sent to the virtual machine (from which the program can access the properties if necessary)

Use arguments unless you clearly know why command - line switches are needed

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>