Back to series
· 13 min read

Compilation and Interpretation: How Does a Program Become Executable Code?


I. Why Do Programs Need Compilation or Interpretation?

The code written by programmers is usually in high-level programming languages, such as C, C++, Java, Python, and JavaScript.

These languages use structures such as variables, functions, conditional judgment, and loops to describe computational logic, making it easy for humans to read and maintain.

For example:

a = 10
b = 20
result = a + b
print(result)

Programmers can directly understand the meaning of this code:

  1. Create variable a, storing the integer 10.
  2. Create variable b, storing the integer 20.
  3. Add the two variables.
  4. Output the calculation result to the terminal.

But the CPU does not understand Python syntax elements such as a, b, and print.

The CPU executes machine instructions that conform to the processor's instruction set architecture specifications, such as data movement, integer addition, comparison, and jump operations.

Therefore, between the source code and the instructions the CPU actually executes, there needs to be a conversion and execution mechanism.

This mechanism mainly includes:

  • Compilation: Convert source code into target code or an intermediate representation.
  • Interpretation: The interpreter reads the program representation and executes operations according to the language semantics.
  • JIT Compilation: During program execution, compile part of the code into machine code.

Together they solve one problem:

How can the computational logic described by the programmer be transformed into operations that a computer can execute?

II. What Is Compilation?

Compilation is the process of converting one program representation into another program representation.

Normally, a compiler reads the source code, analyzes the code structure and semantics, and then generates target code.

The target code may be:

  • Processor machine code.
  • Assembly code.
  • Object files.
  • Virtual machine bytecode.
  • Intermediate representation IR.
  • Executable modules such as WebAssembly.

Therefore, compilation does not necessarily mean directly generating CPU machine code.

1. The Basic Workflow of a Compiler

Taking the C language as an example:

#include <stdio.h>

int main(void) {
    int a = 10;
    int b = 20;
    int result = a + b;

    printf("result = %d\n", result);
    return 0;
}

Compile with GCC:

gcc main.c -o main

In a common GCC toolchain, the compilation and build process can be summarized as:

flowchart TD
    A["C Source Code"] --> B["Preprocessing"]
    B --> C["Compiler Frontend"]
    C --> D["Lexical Analysis"]
    D --> E["Syntax Analysis"]
    E --> F["Semantic Analysis"]
    F --> G["Intermediate Representation IR"]
    G --> H["Code Optimization"]
    H --> I["Target Code Generation"]
    I --> J["Assembler"]
    J --> K["Object File"]
    K --> L["Linker"]
    L --> M["Executable File"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style H fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style K fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style L fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style M fill:#DCEFE5,stroke:#8EBFA5,color:#24563F

The internal structure of different compilers may vary, and some stages may also be merged or adjusted.

2. Preprocessing: Handling Macros and Header Files

In C and C++, preprocessing is usually performed before compilation.

The preprocessor is responsible for handling:

  • #include: Include header files.
  • #define: Define macros.
  • #if, #ifdef: Conditional compilation.
  • #pragma: Pass specific instructions to the compiler.

For example:

#include <stdio.h>

#define MAX_SIZE 100

int main(void) {
    int size = MAX_SIZE;
    printf("%d\n", size);
    return 0;
}

After preprocessing, MAX_SIZE is replaced with the corresponding macro expansion, and the contents of header files are also expanded according to the rules.

You can use the following command to observe the preprocessing result separately:

gcc -E main.c -o main.i

Where:

  • -E: Perform preprocessing only.
  • main.i: Save the preprocessed source code.

Preprocessing itself does not generate executable machine code.

3. Lexical Analysis: Splitting Code into Tokens

Lexical analysis is responsible for converting source code into lexical units, namely tokens.

For example:

int result = a + 10;

It can be split into:

Source Code Fragment Token Type
int Keyword
result Identifier
= Assignment operator
a Identifier
+ Arithmetic operator
10 Integer literal
; Delimiter

The lexer mainly checks whether character combinations conform to the language's lexical rules.

For example, whether variable names conform to identifier rules, whether strings are properly closed, whether there are unrecognizable characters, and so on.

4. Syntax Analysis: Building Program Structure

Syntax analysis is responsible for checking whether combinations of tokens conform to the language grammar.

For example:

int result = a + 10;

It can be parsed as a variable declaration containing:

  • Type: int
  • Variable name: result
  • Initialization expression: a + 10

The compiler usually builds the parsing result into an abstract syntax tree (AST).

For example:

result = a + b * 2;

Its structure can be represented as:

Assignment expression
├── Left side
│   └── result
└── Right side
    ├── a
    └── Addition expression
        ├── b
        └── Multiplication expression
            ├── 2

An AST can clearly express operator precedence, expression hierarchy, and syntactic structure.

The compiler can then directly analyze and transform this tree without having to repeatedly process the original source code text.

5. Semantic Analysis: Checking Whether the Program Conforms to Language Rules

Being syntactically correct does not mean the program is necessarily reasonable.

For example:

int age = "hello";

This code has a type mismatch problem in C.

Semantic analysis mainly checks:

  • Whether variables have been declared.
  • Whether variable scopes are valid.
  • Whether types are compatible.
  • Whether function call arguments match.
  • Whether return value types are correct.
  • Whether identifiers are ambiguous.

For example:

int add(int a, int b) {
    return a + b;
}

int result = add(10, 20);

The compiler can check whether the add function exists and whether the number and types of arguments passed match the function declaration.

Different languages have different semantic checking capabilities. Statically typed languages usually perform more type checking at compile time, while dynamically typed languages may defer some checks until runtime.

6. Intermediate Representation (IR): Building a Unified Program Representation

Intermediate representation (IR) is a form of program representation used internally by compilers.

It sits between the source code and the final target code.

For example:

int result = a + b * 2;

It can be converted into intermediate operations similar to the following:

t1 = b * 2
t2 = a + t1
result = t2

IR helps compilers achieve:

  • Sharing optimization modules across different source languages.
  • Supporting multiple processor architectures for the same source language.
  • Performing unified analysis of program execution structure.
  • Performing data-flow analysis and control-flow analysis.
  • Performing cross-function optimization.

For example, LLVM uses LLVM IR as an important intermediate representation.

define i32 @add(i32 %a, i32 %b) {
entry:
  %result = add i32 %a, %b
  ret i32 %result
}

The LLVM IR here is not native machine instructions for x86 or ARM, but intermediate code that the LLVM compilation infrastructure can process.

7. Code Optimization: Reducing Redundant Computation

The compiler optimizes the program while preserving program semantics.

For example:

int a = 10 * 20;
int b = a + 5;

The compiler can use constant folding to evaluate constant expressions directly at compile time.

The optimized logic can be simplified to:

int a = 200;
int b = 205;

Common optimization techniques:

Optimization Technique Purpose
Constant folding Evaluate constant expressions in advance at compile time
Constant propagation Propagate known constants into other expressions
Dead code elimination Remove code that does not affect the program's results
Common subexpression elimination Avoid recomputing identical expressions
Function inlining Inline some function calls
Loop optimization Reduce redundant operations in loops
Register allocation Place frequently used data in registers

For example:

int a = x * 2;
int b = x * 2;
int c = a + b;

The compiler may recognize that the two occurrences of x * 2 are the same expression and reuse the result.

However, the effectiveness of optimization depends on compiler options, target architecture, program structure, and actual runtime conditions.

8. Target Code Generation: Generating Code for the Target Architecture

The compiler backend converts the intermediate representation into code for the target platform.

For example, the same addition operation:

int result = a + b;

On different processor architectures, it may generate different instruction sequences.

Common targets include:

  • x86-64 machine code.
  • ARM64 machine code.
  • RISC-V machine code.
  • WebAssembly bytecode.
  • Target code used by other virtual machines or runtimes.

Target code generation needs to consider:

  • Instruction selection.
  • Register allocation.
  • Instruction scheduling.
  • Memory addressing modes.
  • Instruction constraints of the target architecture.

9. Assembly and Linking: Generating an Executable File

In traditional toolchains such as GCC, target code is usually first converted by the assembler into object files, and then the linker combines multiple object files and required libraries.

Object files usually contain:

  • Machine instructions.
  • Global data.
  • Symbol table.
  • Relocation information.
  • Debug information.

For example:

#include <stdio.h>

int main(void) {
    printf("Hello World\n");
    return 0;
}

The printf called here usually comes from the C standard library.

The linker needs to resolve the program's references to external symbols and perform the corresponding address and relocation processing.

There are two main ways to link:

Static Linking

The required library code is incorporated into the final executable file.

The advantage is reduced runtime dependence on external dynamic libraries, but the executable file is usually larger.

Dynamic Linking

The required shared libraries are loaded when the program runs.

The advantage is that multiple programs can share library files, and shared libraries are easier to update independently, but dynamic library dependencies must be satisfied at runtime.

III. What Is Interpretation?

Interpretation is when an interpreter reads a program representation and executes operations according to the semantics defined by the language.

Unlike traditional ahead-of-time compilation, interpreted execution usually does not require generating a separate native machine-code executable file in advance.

For example:

name = "Alice"
print("Hello", name)

Execution:

python main.py

The Python runtime processes the source code and performs the corresponding program operations.

1. What Is an Interpreter?

An interpreter is a runtime system responsible for executing programs in a certain programming language.

It usually needs to:

  • Read program code or an intermediate representation.
  • Parse the program structure.
  • Check runtime semantics.
  • Manage variables and objects.
  • Execute operations and control flow.
  • Call runtime libraries.
  • Interact with the operating system.

An interpreter does not simply read code character by character.

Modern interpreters usually first parse the source code, build an AST or other internal representation, and then execute the program through a virtual machine, bytecode interpreter, or other mechanism.

2. The Basic Process of Interpreted Execution

Taking a simplified interpreter as an example:

flowchart TD
    A["Source code"] --> B["Reading and parsing"]
    B --> C["Build internal representation"]
    C --> D["Interpreter execution"]
    D --> E["Read current operation"]
    E --> F["Execute corresponding semantics"]
    F --> G{"Is the program finished?"}
    G -->|No| E
    G -->|Yes| H["Return execution result"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style H fill:#F1F3F5,stroke:#C9D0D8,color:#334155

For example, the interpreter executes:

a = 10
b = 20
result = a + b

It needs to perform operations such as variable binding, numeric object handling, addition, and result storage.

The specific implementation depends on the interpreter's design.

3. An interpreter does not necessarily execute source code directly

This is a very important concept.

An interpreter may execute:

  • The internal syntax tree of the source code.
  • Bytecode.
  • Intermediate representation.
  • Other virtual machine instructions.

For example, CPython usually first compiles Python source code into bytecode, and then the Python virtual machine executes it.

Therefore, interpreted languages may also have a compilation phase.

4. What Are Bytecode and Virtual Machines?

Many languages do not directly convert source code into native machine instructions; instead, they first convert it into an intermediate instruction format.

This intermediate instruction is usually called bytecode (Bytecode).

The program environment that executes bytecode is usually called a virtual machine (Virtual Machine).

1. What is bytecode?

Bytecode is an instruction representation designed for a virtual machine or runtime.

It is usually closer to the execution layer than high-level source code, but it cannot necessarily be executed directly by the CPU.

For example, Java:

public class Main {
    public static int add(int a, int b) {
        return a + b;
    }

    public static void main(String[] args) {
        System.out.println(add(10, 20));
    }
}

Using the Java compiler:

javac Main.java

This generates:

Main.class

This file contains JVM bytecode, rather than complete native machine code generated for a specific CPU.

You can use the following command to view the bytecode:

javap -c Main

You may see a result similar to the following:

public static int add(int, int);
  Code:
     0: iload_0
     1: iload_1
     2: iadd
     3: ireturn

These instructions are recognized and executed by the JVM.

2. What is a virtual machine?

A virtual machine is a system that simulates or implements a specific execution environment through software.

It can provide a unified program execution model so that programs do not have to depend directly on a particular physical processor architecture.

For example:

  • JVM: Java Virtual Machine.
  • CPython virtual machine: the runtime mechanism that executes CPython bytecode.
  • WebAssembly Runtime: the runtime environment that executes Wasm modules.
  • .NET CLR: executes .NET intermediate language and provides runtime services.

A virtual machine usually handles:

  • Instruction interpretation and execution.
  • Memory management.
  • Type checking.
  • Exception handling.
  • Function call management.
  • Garbage collection.
  • Security and runtime constraints.

3. How does a virtual machine execute bytecode?

Take a stack-based virtual machine as an example.

Suppose there is a simple addition operation:

10 + 20

The virtual machine may perform the following operations:

  1. Push 10 onto the operand stack.
  2. Push 20 onto the operand stack.
  3. Execute the addition instruction.
  4. Pop the two operands from the stack.
  5. Push the result 30 back onto the stack.
flowchart TD
    A["Start execution"] --> B["Push 10"]
    B --> C["Push 20"]
    C --> D["Execute ADD"]
    D --> E["Pop two operands"]
    E --> F["Compute 10 + 20"]
    F --> G["Push result 30"]
    G --> H["Continue to next bytecode instruction"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style H fill:#F1F3F5,stroke:#C9D0D8,color:#334155

This is only a conceptual example of a stack-based virtual machine. Different virtual machines may use stack-based, register-based, or other instruction models.

4. Why Is Bytecode Valuable?

Bytecode provides an intermediate layer between source code and the underlying hardware.

It offers several advantages:

Cross-platform execution

The same bytecode can run on compatible virtual machines across different operating systems and processor architectures.

Enables runtime optimization

The virtual machine can analyze actual program behavior during execution and then optimize accordingly.

Provides a unified runtime environment

The virtual machine can manage memory, exceptions, threads, and runtime services in a unified way.

Enables security checks

The virtual machine can check types, access permissions, and instruction validity before or during execution.

But cross-platform does not mean no adaptation is needed at all. Programs may still depend on native libraries, operating system interfaces, hardware features, and runtime environment configuration.

5. What Is the Difference Between Compilation and Interpretation?

The core difference between compilation and interpretation lies in how program translation and execution are organized.

1. Traditional Compilation Model

In the traditional ahead-of-time compilation model, a program is usually first translated into target code and then run.

flowchart TD
    A["Source code"] --> B["Compiler"]
    B --> C["Target code"]
    C --> D["Operating system loading"]
    D --> E["CPU execution"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#F1F3F5,stroke:#C9D0D8,color:#334155

Characteristics:

  • Most code translation is completed before runtime.
  • Optimizations can be made for the target architecture.
  • It can usually produce a standalone native executable.
  • Dynamic libraries and other system dependencies may still be required at runtime.

2. Traditional Interpretation Model

In the interpretation model, the program is read and executed by an interpreter.

flowchart TD
    A["Source code"] --> B["Interpreter"]
    B --> C["Parsing and internal representation"]
    C --> D["Execute program operations"]
    D --> E["Runtime services"]
    E --> F["Operating system and hardware"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#F1F3F5,stroke:#C9D0D8,color:#334155

Characteristics:

  • Program execution work is handled at runtime.
  • An interpreter environment is usually required.
  • It can support dynamic language features.
  • Interpreted execution itself may incur additional overhead.

3. Compiled vs. Interpreted: A Comparison

Comparison dimension Traditional ahead-of-time compilation Traditional interpreted execution
Main conversion timing Before execution At runtime
Typical execution target Native machine code Internal representation of source code or bytecode
Whether a runtime is required Depends on the language and program Usually requires an interpreter
Optimization method Mainly compile-time optimization Mainly runtime execution strategies
Startup cost Depends on program loading and initialization Depends on interpreter and runtime initialization
Cross-platform capability Usually requires platform-specific builds Depends on interpreter availability
Common examples C, C++, Rust Traditional interpreter implementations

Note that compiled and interpreted are not immutable properties of a language itself; rather, they are generalizations about specific implementations and execution methods.

For example, Python can be compiled into native code by other tools, and JavaScript engines also use interpreted execution and JIT compilation.

VI. What Is JIT (Just-in-Time) Compilation?

Traditional compilation is usually completed before execution, while traditional interpretation usually executes an intermediate representation at runtime.

JIT (Just-In-Time Compilation) combines the two mechanisms:

A program first starts execution by interpretation or another form, and then the code that is frequently executed during runtime is compiled into native machine code.

1. Why Is JIT Needed?

When an interpreter executes bytecode, it usually needs to perform tasks such as instruction fetching, opcode dispatch, type checking, and runtime operations.

These operations can introduce additional overhead.

However, not every piece of code in a program is executed frequently.

For example:

public class Main {
    public static int calculate(int x) {
        return x * 2 + 1;
    }

    public static void main(String[] args) {
        int result = 0;

        for (int i = 0; i < 1000000; i++) {
            result += calculate(i);
        }

        System.out.println(result);
    }
}

The calculate function is called repeatedly in the loop and is likely to be hot code.

JIT can identify this kind of frequently executed code and compile it into machine code to reduce the interpretation overhead in subsequent execution.

2. Basic Workflow of JIT

flowchart TD
    A["Source code"] --> B["Ahead-of-time compilation"]
    B --> C["Bytecode or intermediate code"]
    C --> D["Virtual machine startup"]
    D --> E["Interpreted execution"]
    E --> F["Collect runtime information"]
    F --> G{"Does it become hot code?"}
    G -->|No| E
    G -->|Yes| H["JIT compilation"]
    H --> I["Generate native machine code"]
    I --> J["Execute optimized code"]
    J --> K["Continue monitoring runtime state"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style H fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style I fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style K fill:#F1F3F5,stroke:#C9D0D8,color:#334155

3. How Does JIT Determine Hot Code?

JIT usually collects runtime information, such as:

  • Number of method calls.
  • Number of loop iterations.
  • Type distribution.
  • Branch execution behavior.
  • Function call relationships.
  • Object allocation.

When a piece of code meets certain compilation conditions, the runtime may trigger just-in-time compilation.

Different virtual machines may use different hot-code detection strategies and thresholds.

4. Common JIT Optimization Techniques

Function inlining

If a function is called frequently, JIT may inline the function body at the call site to reduce function call overhead.

Type specialization

If an operation consistently handles data of the same type over time, JIT may generate machine code optimized for that type.

Branch optimization

Optimize common execution paths based on branch behavior observed at runtime.

Escape analysis

Analyze whether an object escapes the current method or thread scope, thereby determining whether certain memory allocation and synchronization optimizations can be performed.

Loop optimization

Optimize computations in loops to reduce repeated operations.

5. Deoptimization and Fallback

JIT optimizations usually rely on runtime assumptions.

For example, if a piece of JavaScript code has always been handling integers, the JIT may generate optimized code for integer operations.

If a string is suddenly passed in later, the original optimization assumptions may no longer hold.

At runtime, deoptimization may occur, falling back to a more general execution path.

flowchart TD
    A["Observe types at runtime"] --> B["Types found to be stable"]
    B --> C["Generate specialized machine code"]
    C --> D["Continue execution"]
    D --> E{"Do runtime assumptions hold?"}
    E -->|Yes| D
    E -->|No| F["Deoptimization"]
    F --> G["Restore general execution state"]
    G --> H["Reanalyze and recompile"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#F1E6E8,stroke:#D8AAB5,color:#75404B
    style G fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style H fill:#E8E2F8,stroke:#B6A6DF,color:#514477

JIT does not remain unchanged forever after being compiled once. At runtime, it can continuously collect information and adjust optimization strategies based on actual conditions.

VII. How Are Different Programming Languages Executed?

To understand compilation and interpretation, the most important thing is to observe the real execution models of different languages.

1. C and C++: Ahead-of-Time Compilation to Machine Code

C and C++ usually use ahead-of-time compilation (AOT, Ahead-of-Time Compilation).

For example:

#include <stdio.h>

int main(void) {
    printf("Hello World\n");
    return 0;
}

Compile:

gcc main.c -o main

Execute:

./main

Typical process:

flowchart TD
    A["C or C++ source code"] --> B["Compiler"]
    B --> C["Object file"]
    C --> D["Linker"]
    D --> E["Native executable"]
    E --> F["Operating system loads"]
    F --> G["CPU executes"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style C fill:#E8E2F8,stroke:#B6A6DF,color:#514477
    style D fill:#FFF1D6,stroke:#E6C77A,color:#70551C
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#DCEFE5,stroke:#8EBFA5,color:#24563F
    style G fill:#F1F3F5,stroke:#C9D0D8,color:#334155

Characteristics:

  • Machine code for the target architecture can be generated ahead of time.
  • It usually provides strong low-level resource control.
  • Runtime performance can be improved through compiler optimizations.
  • The generated program usually depends on the target platform and related runtime libraries.

2. Java: Bytecode and the JVM

Java uses javac to compile source code into JVM bytecode.

For example:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Compile:

javac Hello.java

Run:

java Hello

Execution model: