The place where the program starts executing, which is the ** first method called . A method is executed in the flow of calling a method from a method and then calling the next method. The method called first among them is called the entry point ( starting point **). In Java, the main method is set as the entry point for the entire program (the main method is also used as the entry point in multiple languages such as C, C ++, and Objective-C). So it seems good to remember ** entry point = main method ** in Java. The routine that contains the entry point of the entire program is called the main routine, and the class that contains the main method is the main routine.
In Java, rules such as modifiers, names, and arguments used in the main method are strictly defined.
** 1. Access modifier is public 2. static method 3. The return value of the method is void 4. Method name is main (lowercase) 5. Method arguments are only String arrays (or String variadic [^ 1]) **
Also, there is a rule that Java methods must ** always belong to some class.
The general main method based on the above conditions is as follows.
main.java
class Main {
public static void main (String[] args) {
//processing
}
}
By the way, the common argument "args" is the abbreviation of the arguments that represent the arguments.
Also, if the above ** 5 conditions are not met as shown below, it will not be recognized as the main method **.
**-A string type array is not passed as an argument -Passing another argument other than the String type array -The method name is not main ・ Do not use public, static, or void ** etc
The following sites have been very educational. There is also a more detailed explanation of the main method. [Main method indispensable for Java execution, explanation from its mechanism](https://engineer-club.jp/java-main#:~:text=Java%E3%81%AEmain%E3%83%A1 % E3% 82% BD% E3% 83% 83% E3% 83% 89% E3% 81% AF,% E3% 82% AC% E3% 83% 83% E3% 83% 81% E3% 83% AA% E6% B1% BA% E3% 82% 81% E3% 82% 89% E3% 82% 8C% E3% 81% A6% E3% 81% 84% E3% 81% BE% E3% 81% 99% E3% 80% 82)
[^ 1]: ... An argument whose number is indefinite (variable).
Recommended Posts