Difference Program Arguments VM Arguments
Program Argument: This arguments are passed to the program and available through args array of main(String args[]) method as shown example below:
- ProgramArgument.java:
public class ProgramArgument { public static void main(String[] args) { System.out.println("Program arguments:\n"); System.out.println("args[0] -->"+args[0]); System.out.println("args[1] -->"+args[1]); } }
- As you see above we will pass two program argument and print its value. I will use eclipse to pass argument and run:
- Now run this program it will print value as below:
VM Arguments: This arguments are passed to the virtual machine which instruct VM to take some action.You could pass VM argument memory size, file path etc… which you can access by calling to System.getProperty() as shown in example below:
- VMArgument.java:
public class VMArgument { public static void main(String[] args) { System.out.println("Name: "+System.getProperty("name")); } }
- We will pass some VM argument as below from eclipse:
- When you run this program it will print below value on console:
- For more information please refer oracle document here