What is public static void main(String args[]) ?


 public static void main(String args[]) 

Above line shows the way of presenting the main method in Java, and it is a point from where the Java program starts running. Here, each and every word has its own meaning and objective.
Let discuss them one by one :

public : It is an access modifier. Access modifiers actually defines accessibility level of the method i.e. who can access this method. Public means that this method is accessible to all (i.e. anyone can call this method).
Declaring main method with public access modifier is necessary as main method is called by JVM itself.

static : It is a keyword, which allows to call the method without creating an object (instance) of the class. Keyword ‘static’ is must because the main() method is called by the JVM before the creation of any object.

void : It is a return type. Return type gives information about the type of value (int, char, float), which is return by the method after completion; ‘void’ indicates that method return nothing.

main() : It is the name of the method.

String args[] : It indicates an array of string objects (i.e. statement for declaring an array of objects of String class). This array of string objects is used for taking command line arguments.

Related Post

2 Replies to “What is public static void main(String args[]) ?”

Leave a Reply

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

The reCAPTCHA verification period has expired. Please reload the page.