Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:59+00:00 2026-05-27T17:27:59+00:00

Let us assume a Java application, accepting an integer command line argument, say bubu

  • 0

Let us assume a Java application, accepting an integer command line argument, say bubu.

Assuming one uses a decent command line parser (and I do – https://github.com/jopt-simple/jopt-simple) plus keeping in mind the -D java switch, these are some of the typical ways to pass this command line parameter:

  1. --bubu 5 (or --bubu=5 or --bubu5)
  2. -Dbubu=5

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 Integer.getInteger("bubu")

I am kinda puzzled. What should I use? Using the system property facility:

  • seems to cost nothing
  • does not depend on any command line parser library
  • provides convenient (albeit unexpected) API to obtain the values

As far as I can see, the only cons is that all the command line options have to use the -D flag.

Please, advice.

Thanks.

EDIT

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 https://stackoverflow.com/users/571407/jb-nizet

EDIT2

Let me be more focused here. Is there any serious reason (besides esthetics) not to use the system parameters, like always?

EDIT3

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.

Therefore, I have to be prudent and disambiguate my system properties beforehand. So, no more bubu, it is com.shunra.myapp.bubu now. Meaning that instead of a simple

-Dbubu=5

I have

-Dcom.shunra.myapp.bubu=5

which becomes less attractive for a simple command line application.

Another reason is given by Mark Peters, which is pretty good to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:28:00+00:00Added an answer on May 27, 2026 at 5:28 pm

    I’d argue that the advantage Fortyrunner cites is actually the most significant negative for system properties–they are available to anyone who asks for them.

    If the flag or option is meant to be a command-line option, it should be available to the layer or module of your code that deals with taking input from the command line, not any code that asks for it.

    You can get some destructive coupling from global state, and system properties are no different than any other global state.

    That said, if you’re just trying to make a quick and dirty CLI program, and separation of concerns and coupling is not a big concern for you, system properties give you an easy method that however leads to (IMO) poor user experience. Some getopt library will give you a lot more support for building a good CLI user experience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we have a java.util.LinkedList containing a few hundreds of elements. One possibility
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
In Java, constructors cannot be recursive. Compile time error: recursive constructor invocation. Let's assume
Let's assume I want to send many messages between 2 programs made in java
I've been giving a application to work on that uses a Java EE application
One more question that relates to this interface . Let's say that I would
Let's assume I have a file named Main.java with the following code: public class
A little question regarding performance in a Java web app. Let's assume I have
Let me first say that I have quite a lot of Java experience, but
How does one process large binary data files in Clojure? Let's assume data/files are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.