JAVA MAIN METHOD
The Java main method is the entry point for any standalone Java
application. When the Java Virtual Machine (JVM) executes a Java
class, it looks for and invokes this specific method to begin
program execution.
The signature of the main method must always be:
public static void main(String args[]) {
// Program logic goes here
}
• public
This access modifier ensures that the main method can be
accessed and executed by the JVM from anywhere, as it's the
program's starting point.
• static
The static keyword allows the JVM to call the main method
without needing to create an instance of the class. This is crucial
because the main method is the very first method to be executed,
and no object exists yet at that stage.
• void
This indicates that the main method does not return any
value. Once the main method finishes execution, the Java
program typically terminates.
• main
This is the fixed name of the method that the JVM recognizes as
the entry point.
• (String args[])
This specifies that the main method accepts a single argument,
which is an array of String objects. These strings represent any
command-line arguments passed to the Java program when it is
executed.