Is there a use-case for custom JVM parameters (what are custom jvm properties?) that is impossible to replicate using regular program arguments? In other words, are they strictly necessary or simply a programming convenience?
Here is a use case for JVM arguments that is not strictly necessary:
java -jar -DmyCustomArg="my_value" MyFile.jar
Where somewhere in MyFile is the following code, pulling out the property:
String s = System.getProperty("myCustomArg");
This property is not strictly necessary because we can replace it as follows:
- Declare a map class in MyFile e.g. a HashMap mapping key value pairs, and use the singleton pattern to instantiate one instance of this to be used across the entire program
- Read in a program argument called myCustomArg, see Proper usage of Java -D command-line parameters for the difference between program and JVM System arguments.
- Add code to MyFile to load the program argument into the hash map
- Replace the above system property retrieval with hash map retrieval
Obviously, to do all of the above would be a lot less convenient than just adding & retrieving a JVM property. But my question: is there a qualitative difference between the two, i.e. is there a use case for JVM parameters where there is no way to achieve the same thing with regular program arguments? Or, are custom JVM arguments that we add simply a convenience that lets us avoid declaring and using our own Properties object like a Map?