What Is Public Static Void Main Method in Java?

0
20
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Main method in Java
Main method

Main method in Java

For standalone java program,the class name should be same as file name. we will get a compilation error if otherwise.The class should contain a main() method with the given signature:


public static void main(String[] args){}
 

Conceptually every java program must include a main() method to run independently.main() is the starting point or triggering point for interpreter to begin execution.A java program can have n-numbers of classes but only one of them include  a main() method to initiate the execution.

public-> is available for the world to use. check this link for more.
String[] args->It declares a parameter name args of type String array.The argument to the main is an array of String objects.In IDE mode of development,they will never be used in general,but they hold the arguments invoked on the command line.
Static:Static keyword declares this method /variable as one that belongs to the entire class and not part of any objects of the class. The main() method must always be declared as static since the interpreter uses this method before any objects are created.Non static things belong to object.If main is non static,we can not have main method until we create an object.But when we start java code,no objects have been created yet. The statements that are executed in the main method start creating objects.
void–>this modifier declares that main() method does not return any value. 

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here