What is first argument of String array in main method

What is first argument of String array in main method

Answer: It depends how you run your program. If you pass argument during run time as shown example below: 

package com.javahonk;

public class MainMethodTest {

	public static void main (String[] args) {
        for (String s: args) {
            System.out.println(s);
        }
    }

}

 

If you run above program and pass below value with input arguments which shows in in italics will show you out put below:

java MainMethodTest main method test argument
main
method
test
argument

main is first argument of main method.

If you don’t pass anything and run program like : java MainMethodTest then first argument will be empty.

Leave a Reply

Your email address will not be published. Required fields are marked *