title: Java: using system parameters vs "regular" command line options
body: <p>Let us assume a Java application, accepting an integer command line argument, say <code>bubu</code>. </p>
  
  <p>Assuming one uses a decent command line parser (and I do - <a href="https://github.com/jopt-simple/jopt-simple" rel="nofollow noreferrer">https://github.com/jopt-simple/jopt-simple</a>) plus keeping in mind the -D java switch, these are some of the typical ways to pass this command line parameter:</p>
  
  <ol>
  <li><code>--bubu 5</code> (or <code>--bubu=5</code> or <code>--bubu5</code>)</li>
  <li><code>-Dbubu=5</code></li>
  </ol>
  
  <p>Where the first one is the program argument and must be handled by the application using some command line parser, whereas the second is the VM argument and is already parsed by java, making it available as <code>Integer.getInteger("bubu")</code></p>
  
  <p>I am kinda puzzled. What should I use? Using the system property facility:</p>
  
  <ul>
  <li>seems to cost nothing</li>
  <li>does not depend on any command line parser library</li>
  <li>provides convenient (albeit unexpected) API to obtain the values</li>
  </ul>
  
  <p>As far as I can see, the only cons is that all the command line options have to use the <code>-D</code> flag.</p>
  
  <p>Please, advice.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Another pros for the system parameters - "they're usable even when the application is not a stand-alone app starting from a main, but also when the app is a webapp or a unit test." - thanks <a href="https://stackoverflow.com/users/571407/jb-nizet">https://stackoverflow.com/users/571407/jb-nizet</a></p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Let me be more focused here. Is there any serious reason (besides esthetics) not to use the system parameters, like always?</p>
  
  <p><strong>EDIT3</strong></p>
  
  <p>OK, I think I get it now. If my code is likely to be loaded by a web application, then there is an issue of a potential name clash, since other web applications hosted by the same web container share the system property space with my code. </p>
  
  <p>Therefore, I have to be prudent and disambiguate my system properties beforehand. So, no more <code>bubu</code>, it is <code>com.shunra.myapp.bubu</code> now. Meaning that instead of a simple </p>
  
  <pre><code>-Dbubu=5
  </code></pre>
  
  <p>I have</p>
  
  <pre><code>-Dcom.shunra.myapp.bubu=5
  </code></pre>
  
  <p>which becomes less attractive for a simple command line application.</p>
  
  <p>Another reason is given by <a href="https://stackoverflow.com/users/228171/mark-peters">Mark Peters</a>, which is pretty good to me.</p>