Java main() method

main is a Java method. main is a method that any program needs in order to execute.  public static are just keywords (modifiers) that Java uses to determine the method type and must always be in all lower case letters.  void is the return type of the method. The void return type means that the method does not return any value. At last main has String args[] inside parenthesis. In Java, all variables that user need to give to the method in order to work go in there as a comma separated list. These are called parameters. Each parameter is added by giving type and name for that variable that user will use in that method only. main needs to have the String[] args parameter in order for programs to work.

Java has following main method heading:

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

public static void main(String.. args){}

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

class: class  is used to declare a class .

public: public  is an access modifier which represent visibility for all.

static: static is a keyword, if we declare any method with static ,it is known as static method. Then no need to create object to invoke the static method.

void: void is return type,  means it doesn’t return any value

main: main is a startup of the  java program.

String[] args : String[] args  is used for command line argument in java.

System.out.println: System.out.println is used to print statements.

Leave a Reply

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