Skip to main content

Main method in java

· One min read
Sandeep Bhardwaj

public static void main(String arg[])

In Java we write public static void main (String args[]) instead of just main because:

public static void main(String arg[])   
{

}

public


The main method must be public because it is call from outside the class. It is called by jvm.

static


The main method must be static because without creating an instance jvm can call it.
If the main method is non static then it is must to create an instance of the class.

void


Main method doesn't return anything therefore it is void also.

Strings args[]


It is used for receiving any arbitrary number of arguments and save it in the array.