What is argument of main method

What is argument of main method

Answer: Let’s understand first difference between argument and parameter because I have seen people get confused with this word:

argument: An argument is the instance passed to the method during run time.
parameter: A parameter is what appears in the definition of the method

Now let’s come back on our main question: argument of main method: If you pass value during run time then that will be populated in String args[] as an argument and if you don’t pass anything that will be empty. See example below displays each of its command-line arguments on a line by itself:

package com.javahonk;

public class MainMethodTest {

	public static void main (String[] args) {
        for (String s: args) {



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

java MainMethodTest main method test argument

Leave a Reply

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

I am not Robot *