Explain public static void main(String argos[]) in Java?

The main() method is the entry point for any program in java language. In the expression public static void main(String argos[]), each keyword has significance as mentioned below:

  • Public: It’s an access specifier which is used to specify the accessibility of a method in java. Here, Public means anyone can access the method or the class.
  • static: the static keyword in java identifies the main method as class-based, which means it can be accessed without creating an object/instance. Static methods can b3e directly called by the Java Virtual Machine(JVM), which in turn saves extra memory allocation.
  • void: void is a return type in java, which means the main method will not return any value back.
  • String args[]: String argos[] or String[] args is an array of String objects which stores the command line arguments. Here the argument is an array of types of java. Therefore, it’s passed as the parameter in the main() method.