[Java] About Java entry points

1 minute read

What is an entry point?

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.

5 conditions of main method

In Java, rules such as modifiers, names, and arguments used in the main method are strictly defined.

** 1. Access modifier is public

  1. static method
  2. The return value of the method is void
  3. Method name is main (lowercase)
  4. 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.


class Main {

    public static void main (String[] args) { 

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 **

Reference site:

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