Tuesday 4 April 2017

Explain public static void main(String[ ] args) in java.

Each word has certain meaning associated to it. 
Let’s find out what each word means:

public

public keyword is an Access Modifier. It tells that the main() method can be accessed by any class irrespective of the package to which it belongs.

static

The static keyword signifies that the main() method is a class method. To access it one does not require to create instance of the class to which this method belongs.

This is the reason that JVM is able to call this method even before any instance of the class containing main() is created.

void

void is just a return type. The void in the code signifies that the main() method is not going to return any value.

main()

This is the name of the method.
main() method is the entry point of any core java program. When you run your code, JVM search for this method with the same signature as shown in the code above.

String args[]

It is used for the command line argument. (working of String[] args)

System.Out.Print()

It is used to print the statement. (See internal working here)

No comments:

Post a Comment

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.