EMZETT.
Login

void main (Program Entry Point)

In short: The special method/function whose execution starts a program — the “starting point” that the operating system or runtime environment automatically calls when the program launches.

In more detail: In many languages (Java, C, C++), this entry point is called main and has a fixed, prescribed signature that the runtime environment recognises and calls automatically — from there, the rest of the program is kicked off. main often accepts an array of command-line arguments, through which the program can receive additional parameters at startup.

In Depth

A program consists of many functions/methods — the runtime environment therefore needs to know WHICH of them should be called first when the program starts. Instead of leaving that to chance or the order in the source code, most languages require a method with a fixed, recognisable name and a fixed signature:

public static void main(String[] args) {
    // execution starts here
}

Every part of this signature has a reason: public makes the method callable from outside (from the runtime environment), static allows the call WITHOUT first having to create an object of the class (the runtime environment can call main before anything of the program “exists” at all), void means the method returns no value to the caller (the program’s end and any error code go through a separate mechanism), and String[] args accepts the command-line arguments passed at program startup.

java MyProgram hello world
# args = ["hello", "world"] within the main method

Not all languages require an explicitly named main function. Python, for example, simply executes the top-level code of the file from top to bottom when the program starts — there’s no enforced entry-point name, even though the convention if __name__ == "__main__": has become established to mark code that should only run when the file is executed directly (not when imported as a module into another program).

The return value of the program itself (not the main method) — the so-called “exit code” — is a separate concept: 0 usually signals to the operating system “terminated successfully”, any other value indicates an error. This matters for scripts and automation, which decide based on the exit code whether a previous step was successful before the next one starts.

See also: void, User Input