|
Answer» The public static void main(String ARGS[]) is the main method of the Java Program. It is the entry point of any Java Program. A Java program cannot be executed without the main method. The syntax of the main method is as follows: public static void main(String args[])Only the args can be changed to a different name but the rest of the method carries the same syntax. Let us analyze the main method by breaking it up: - public: This is the access specifier/access modifier of the main method. It should be public to allow the class to access it. In case of violation of the same, the program will SHOW an error.
- static: At the start of the runtime, the class is devoid of any object. Thus, the main method needs to be static so that the Java Virtual Machine can set the class to the MEMORY and CALL the main method. If the main method is not static then the JVM won’t be able to call it due to the absence of an object.
- void: It is the return type of the main method. Each and every method in Java must have a return type. The main method doesn’t return any value that can be accessed by the other methods as the main method can’t be called in any other method. As soon as the main method finishes its execution the program terminates. Hence it wouldn’t be of any use to return a value.
- main: It is the name of the main method. This name is ALREADY set and can’t be changed. If any changes are made to the main keyword then the compiler tells that the main method couldn’t be found.
- String args[] : The main method can accept a single argument which is of the String type. They are also called command line arguments. They can be used and manipulated as normal arguments in the code written in the main method. They are written along with the execution statement.
|