A Hello World program is the smallest possible example that writes the message "Hello, World!" to standard output, and every mainstream language ships with a canonical version that demonstrates its entry point, syntax rules, and standard-output mechanism. Twelve of those canonical programs are collected side-by-side in the Hello World in Different Programming Languages reference, covering JavaScript, Python, Java, C, C++, C#, Go, Rust, Ruby, PHP, Swift, and Kotlin in their ordinary command-line form. Each row names a typical source filename and the broad runtime that executes it, so a learner can compare syntax without mixing in unrelated build systems or graphical application templates. The reference is read-only: it filters and copies example text and never invokes a compiler, opens a file, or executes code on your behalf. You still need the matching local toolchain to actually run anything, and that separation matters because a single line of text can be valid in an interactive shell while a saved application requires an entry function, class, package declaration, compiler invocation, or project file.

how to say hello world in different programming languages
how to say hello world in different programming languages

What the Twelve-Language Reference Covers

The reference exposes one record per language, each with a unique ID, the language name, a typical source filename, the runtime family, and the full code snippet. The included languages are JavaScript, Python, Java, C, C++, C#, Go, Rust, Ruby, PHP, Swift, and Kotlin, picked because they represent the mainstream spread of interpreted, compiled-to-bytecode, and compiled-to-native workflows. The snippets are deliberately compact and follow the conventional command-line entry point for each language. Eight of the examples are checked against official language documentation, and the rest are aligned with a cross-language comparison source so the surrounding phrasing matches the references used in tutorials.

What the reference does not cover is just as important as what it does. A one-line example can demonstrate standard output, but it does not teach package management, user input, error handling, automated tests, project layout, deployment, or idiomatic architecture. The reference never claims that a copied snippet is a complete production project. Compiled languages still require an explicit build step before execution, interpreter-oriented examples still depend on an installed runtime and the correct version-selection command, and JavaScript behaves differently in a browser developer console than it does under Node.js.

Why Hello World Differs Between Languages

The differences across the twelve programs are not decorative. Quotation marks, semicolons, braces, indentation, include or import statements, and newline escapes are language syntax, and each example shows the minimum legal form for that language. Python uses indentation to delimit blocks, so its Hello World is a single top-level call to the built-in print function. C-family languages use braces and an explicit main entry function, so their snippets look heavier even when the printed message is identical. Java requires a class wrapper around main, while Kotlin offers a top-level main function that compiles to the same JVM bytecode. C# normally lives inside a .NET project with a Program class, which is why a one-line Console.WriteLine call still needs surrounding structure.

Output targets also vary. Most of the twelve write to standard output of the host process, but JavaScript can run either in a browser developer console or under Node.js, and the surrounding globals and module rules differ between those two environments. Browser JavaScript writes to the console rather than to the visible page. The output message itself uses English punctuation and a conventional comma, and changing the text is safe once the program works, but Unicode output can expose terminal encoding and font issues that are unrelated to the language.

How to Find, Copy, and Run a Hello World Example

The reference is designed to fit inside a small, repeatable loop. The steps below keep the experiment deliberately small so that any failure points to the toolchain rather than to source code that you wrote yourself.

  1. Search by language name, runtime, typical filename, or a small code fragment such as println, printf, console.log, or fmt.Println. The search is text-based and works against the normalized fields and the snippet body.
  2. Copy the complete example exactly as displayed. Do not paraphrase, omit closing braces, or merge lines; the snippets are sized so that copying them whole keeps the program valid.
  3. Save the block into the plain-text filename shown next to the language. Use a text editor that preserves ASCII punctuation, straight quotes, and the line endings your toolchain expects. The official Python documentation for the built-in print function describes the same minimum call shown in the reference.
  4. Follow the current official compiler or runtime instructions for that language. Compiled languages need an explicit build step, interpreter languages need an installed runtime plus a command that selects the intended version, and JavaScript can run in a browser console or Node.js with different surrounding rules.
  5. Confirm the output. The expected line is the conventional "Hello, World!" message. If the program runs but prints nothing visible, check whether the language wrote to standard output or to a developer console, and whether stdout was buffered or redirected.
  6. Once the first run succeeds, add a tiny test, version-control the source, and learn the language's official build and dependency workflow. The Rust Book's Hello World chapter, for example, walks through the same first program plus the toolchain setup at doc.rust-lang.org.

Twelve Languages at a Glance

The table below compares the conventional filenames, build or runtime model, and output target for each of the twelve languages. Filenames are typical rather than mandatory, and the runtime column names a broad family rather than a specific version.

Language Typical source filename Build or runtime model Output target
JavaScript hello.js Browser console or Node.js Stdout or developer console
Python hello.py CPython interpreter Stdout
Java HelloWorld.java Compiles to JVM bytecode Stdout
C hello.c Compiles to native executable Stdout
C++ hello.cpp Compiles to native executable Stdout
C# Program.cs (or Hello.cs) Build within a .NET project Stdout
Go hello.go Compiles to native executable Stdout
Rust main.rs Compiles to native executable Stdout
Ruby hello.rb Ruby interpreter Stdout
PHP hello.php PHP interpreter Stdout
Swift hello.swift Compiles to native executable Stdout
Kotlin Hello.kt Compiles to JVM bytecode Stdout

The split between compiled and interpreted runtimes is the most useful signal in the table. C, C++, Go, Rust, and Swift commonly produce a native executable from a single source file. Java and Kotlin compile to JVM bytecode and still need a JVM to run. C# is closest to Java and Kotlin in structure but builds inside a .NET project. Python, Ruby, and PHP are interpreter-oriented, which means the snippet can be valid in an interactive shell but still requires a runtime plus a version selector when saved to a file. JavaScript can run in either a browser or Node.js, and the surrounding globals and module rules differ between the two.

Pitfalls When Copying Snippets Between Languages

Several recurring mistakes appear when learners copy a Hello World snippet from one context to another. The most common is pasting into a rich-text editor that replaces straight quotes with curly quotes, which breaks every C-family example because the compiler reads curly quotes as ordinary characters rather than as string delimiters. Saving with a text encoding that the toolchain does not recognize is a close second, particularly for the small number of characters such as the comma, the exclamation mark, and the newline that change between encodings.

Indentation and semicolons also trip up cross-language copying. Python uses indentation for blocks, so removing four spaces from a Python snippet is a syntax error. Languages such as JavaScript, Java, C, C++, C#, Go, Rust, and Swift allow or require semicolons, and the rules differ even between those languages; Go and Rust insert them automatically in some cases, while Java and C# expect them on most lines. If compilation fails, the first diagnostic usually points to the line with the missing or extra punctuation. Confirming the filename, the toolchain version, and the command-line invocation usually resolves the next layer of failures.

Two output behaviors deserve explicit attention. Browser JavaScript writes to the developer console rather than to the visible page, so a script that calls console.log will not change the DOM. Standard output may also be buffered or redirected, which is why a script that prints nothing visible is not necessarily broken. Production applications should use suitable logging rather than leaving tutorial prints throughout performance-sensitive or privacy-sensitive code, and a Hello World exercise is a good moment to learn that lesson. Character encoding matters at this step too, since terminal fonts and code pages can render non-ASCII bytes inconsistently; the ASCII Code for Programming and Data Tasks guide covers the seven-bit basics that Hello World snippets rely on.

What Comes After the First Successful Run

The Hello World reference treats the first successful run as a checkpoint rather than a destination. The next step is a small test, even if it only asserts that the output contains the expected message. After that, putting the source under version control preserves the working state, makes the experiment reproducible, and gives you a baseline against which later changes can be diffed. The reference deliberately stops there; toolchains, project templates, dependency managers, packaging, and deployment each live in their own ecosystem, and the official documentation for the chosen language is the correct place to learn them.

The twelve records in the reference are protected by table-size and uniqueness tests, and the verified examples are checked against official language documentation and a cross-language comparison source. Toolchains evolve, so current commands and project templates should always be verified upstream before you trust them in a real build. Keeping the first experiment deliberately small and reproducible is the entire point. A Hello World program is a starting line, not a finish line.