• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Every programming language needs a well-defined entry point where execution begins. Without a standard structure, developers would need to configure build tools and runtime environments with complex startup instructions, making simple programs unnecessarily difficult to write and run.

Core Idea

A Java program is organized around classes. The entry point is a special main method with a specific signature — public static void main(String[] args) — that the JVM calls to start execution. Every executable Java program must have exactly one such method.

How It Works

The JVM loads the class specified on the command line, looks for the main method with the exact signature, and invokes it. The String[] args parameter receives command-line arguments. The program executes line by line from the first statement in main until the method returns or System.exit() is called.

Visual Explanation

java_program_structure Source Hello.java public class Hello {  public static void main(...) {    System.out.println("Hi");  } } JVM JVM Launcher Source->JVM java Hello Main main() Method Entry Point JVM->Main finds and invokes Body Method Body Statements Execute Main->Body executes line by line End Program Terminates Body->End method returns

Semantic Network

semantic_java_structure THIS Program Structure CLASS Java Classes THIS--CLASS built from METHOD Java Methods THIS--METHOD built from ACCESS Access Modifiers THIS--ACCESS builds into CMD Command Line Args THIS--CMD related

Key Properties

  • Entry point signature: public static void main(String[] args) is the required form
  • Class scope: Every Java program is a class; no standalone functions
  • Args array: Command-line arguments arrive as a String array (possibly empty)
  • Exit: System.exit(0) for explicit termination with status codes

Connections

  • Built from: Java Methods — the main method follows the same declaration rules
  • Built from: Access Modifiers — main must be public for the JVM to access it
  • Builds into: Java Methods — the main() method follows standard method declaration rules
  • Related: Java Platform Independence — the compile-once-run-anywhere model that this structure enables

Edge Cases & Gotchas

  • Missing main(): java command throws NoClassDefFoundError: no main method
  • Wrong signature: Changing any modifier breaks JVM lookup
  • Args can be null in some environments, though normally an empty array
  • Static context: main is static — no access to instance fields without creating objects