Java Program Structure

Java Program Structure

Java Program Structure


Why is main method in java public,static,void?

Signature of main() Method:

The controlling class of every Java application must contain a main() method having one of the following signatures (this author prefers the first signature as being the most descriptive of an array of String references which is what is passed in as an argument).

Public static void main(String[] args)

Public static void main(String args[])

public

  • The keyword public indicates that the method can be called by any object. A subsequent lesson will discuss the keywords public, private, and protected in more detail.

static

  • The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class. This is used by the Java interpreter to launch the program by invoking the main method of the class identified in the command to start the program.

void

  • The keyword void indicates that the method doesn’t return any value.

args

  • The formal parameter args is an array of type String, which contains arguments entered at the command line. Note that the args parameter must be specified whether or not the user is required to enter a command-line argument and whether or not the code in – Write the method signature for the main method in a Java application.

public static void main(String[] args)

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

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

*

Time limit is exhausted. Please reload CAPTCHA.