Java Main Method - chrisbitm/python GitHub Wiki

public class Main {
  public static void main(String[] args) {
    System.out.println("Power Rangers is awesome");
  }
}
  • public class Main declares a Class named Main.
  • public static void main(String[] args)
    • This defines the main method. Every Java program must have a main method where execution starts.
    • public means it can be accessed from anywhere.
    • static means it belongs to the class and not an instance of the class.
    • void means the method doesn’t return anything.
    • String[] args is an array that allows passing arguments from the command line when running the program. *System.out.println("Power Rangers");
    • This prints "Power Rangers" to the console.
    • System.out refers to the standard output stream.
    • println() prints the text followed by a new line.

Every Statement must end with a semi-colon ;

The main method must be public because it's the entry point of a Java application, and the Java Virtual Machine (JVM) needs to call it from outside the class.

If you change it from public` to private or remove it altogether, the JVM won't be able to access and run the method, resulting in an error.