public static void main string args meaning in java
In java main() method is the initial point for execution of the program. If a program doesn’t contain the main method, the program will not execute. JVM(java virtual machine) starts the program running in java. For writing this method, we need to follow the syntax.
public static void main(String args[]);
From the syntax :
It contains different keywords. Each keyword has its value.
public keyword
The public is one of the access modifiers in java. Public keywords identify the JVM machine for the program's execution. This keyword is used for classes, methods, and constructors. Can use the keyword for accessing everywhere. We use public keywords to give identity for one or more classes in a program.
Example
class Main{
private static void main(String[] args)
{
System.out.println("I am a student");
}
}
Output

static keyword
A method can be static if it contains the static keyword. By using a static void, the main method can be called directly without creating an object, so by using this method, there is no need to create an object.
Example
class Main{
public void main(String[] args)
{
System.out.println("I am a student");
}
}
Output

void keyword
When compared to the c language, java has no return datatype. The void keyword implies that the compiler understands that it does not contain the return type in the main method.
Example
class Main{
public static int main(String[] args)
{
System.out.println("JAVA");
return 1;
}
}
Output

main() method
Java Virtual Machine predefined the default signature. This method is called Java Virtual Machine for running the program for each line and executing the result. The main method can be overloaded.
String args[
The main() method is used for getting input from the user. The input given by the user treated like a String, called a string array. Holding up the values in the command line arguments in the form of string args[] is used. String args[] is the array name for storing string values, which means it can store strings. The args array can store numbers, but they are in string format. The values passed into the main() method are called arguments, which are used for storing input.
What results when the main() method doesn’t contain String args[]?
If the main method doesn’t contain string args[], the compiler will compile the program, but it doesn’t run. Due to the absence of string args[], JVM does not recognize the main method. JVM will recognize the main() method if it contains arguments passed in it.
Process of execution
At the initial state, the Java Virtual machine will run the code's static block as it is very easy to access the static memory area. After that, the methods declared in the static block are executed, and the JVM will create an object. At last, the instance methods will get executed. The static block in JVM is in top priority. Before execution of the main block, it checks in the static block.
Example
class Main
{
static //static keyword
{
System.out.println("STATIC block");
}
public static void main(String args[]) // main method
{
System.out.println("Static methods");
}
}
Output

From the above program, we can understand that JVM will initially execute the static block in the program, and then it looks for the main() method. If the program doesn’t contain any main method, it returns an error that the main method is not found.
Program does not have main() method
class Main
{
static //static method doesn't contain the main method
{
System.out.println("Static block doesn't contain main method()");
}
}
Output

Hence the main method is very important in a program. The main() method can be interchanged in the following way:
static public void main(String args[])
The main() method can use a different name in String as:
main(String[] x)
There are more two ways the writing the main() method:
- static public void main(String []x)
- static public void main(String…args)
The string argument is used to accept null or more values. For this, three dots needed to be included.
Overloading main() method
class Main
{
public static void main(int c) //two same methods in a single program
{
System.out.println(c);
}
public static void main(String args[])
{
System.out.println("Main method get invoked");
main(67);
}
}
Output
