System parameters
System-level global variable, which can be accessed anywhere in the program. The highest priority is overridden by the configuration of the same name in the program.
The standard format of system parameters is: -Dargname=argvalue, and multiple parameters are separated by spaces. If there are spaces in the middle of the parameter value, it is enclosed in quotes.
Among them, the parameter name can be Java default, and such parameters are automatically recognized and effective by the JVM virtual machine. For example, -=UTF-8 is used to specify the file encoding format; it can also be user-defined, for example, -Dmy=user, the program can read the parameter value and execute related logic.
The parameter key-value pairs set in the virtual machine system parameters can be used ("propertyName") to obtain the corresponding parameter values in the program.
public static void main(String[] args) { String result = ("argname"); ("argname: " + result); }
Running parameters
The parameter value passed in when the main method is executed. If there are multiple parameters, separate them with spaces.
The general format of the main method is: public static void main(String[] args), where Stringp[] args is a variable that stores running parameters and can be used directly in the program.
public static void main(String[] args) { if ( > 0) { for (int i = 0; i < ; i++) { ("Third" + i + "The parameters are: " + args[i]); } } }
Parameter settings in the command line
The basic format of the java command is java [-options] class [args...], where:
[-options] Configure Java system parameters
[args…] Configure Java running parameters
Example: java -=UTF-8 -Dargname=argvalue Test hi a b c d
Parameter settings in IDEA
- Run- Edit Configurations... - Spring Boot - App - Configuration - Environment
- VM options: Set system parameters
- Program arguments: Set running parameters
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.