Its public static void main for the following reasons.
public since we need to access it outside out class
static since we dont create an instance of the class for executing main
void is the return type (since we are calling from outside return value serves almost no purpose.
string args[] is for storing the arguments as an array

when u call the java class with arguments the arguments are stored in the array and you can access them later in your code.

1) The Java Virtual Machine is started ("java") and it attempts to load the specified class ("<classname>").
2) When the class is successfully loaded, the JVM looks for the main() method entry-point and passes the remaining command line parameters ("<argument1> ...") to this method as an array of Strings.

That's why if you make a typo on the command line, step 1) responds with "NoClassDefFoundError".
If main() is not defined correctly, then step 2) responds with "NoSuchMethodError: main"

Just for information: The main method signature should *always* be the same. The Java Virtual Machine specifically looks for this method, so if you were to write:

public static void main()
{
.
.
}

It wouldn't run.

Also, because Java is fairly relaxed about array definitions, you can also use:

public static void main(String[] args)

(This is the preferred way to define an array - ie. with the [] following the class/type rather than the variable - but both will work OK)

0

Featured Post

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children.
So, while being a kid is still extremely important, it’s also …

In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…