Hello World compared across 16 programming languages

The classic first program: printing some text. Here is what it looks like in every language.

Python JavaScript TypeScript Java C C++ C# Go Rust PHP Ruby Swift Kotlin SQL Bash HTML & CSS

PyPython

print("Hello World!")

print outputs text to the console – no main, no parentheses needed.

JSJavaScript

console.log("Hello World!");

console.log writes to the console – no main, no class needed.

TSTypeScript

const gruss: string = "Hello World!";
console.log(gruss);

Like JavaScript, only with the type annotation : string after the name. tsc compiles, node runs the result.

JvJava

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

Every Java program needs a class with main. Start it with java Main.java.

CC

#include <stdio.h>

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

main is the entry point, printf prints text. Without \n there would be no line break. Compile with: gcc -Wall -o hallo hallo.c.

C++C++

#include <iostream>

int main() {
    std::cout << "Hello World!\n";
}

std::cout writes to the console, main is the entry point. Compile with g++ -std=c++20 hallo.cpp -o hallo.

C#C#

Console.WriteLine("Hello World!");

Thanks to top-level statements, a single line is enough – no class and no Main needed.

GoGo

package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
}

Every executable program needs package main and a main function; fmt.Println prints a line. Start it with go run ..

RsRust

fn main() {
    println!("Hello World!");
}

main is the entry point, println! is a macro (recognizable by the !). Run it with cargo run or rustc hallo.rs.

PHPPHP

<?php
echo "Hello World!\n";

echo prints text. Run it with php datei.php or via the web server. is a line break.

RbRuby

puts "Hello World!"

puts prints text with a line break. No main, no parentheses and no semicolon needed. Run it with ruby datei.rb.

SwSwift

print("Hello World!")

print outputs text: no main, no braces around the block, no semicolon. Run it with swift hallo.swift.

KtKotlin

fun main() {
    println("Hello World!")
}

No class wrapper, no semicolons: main can live directly at the top level.

SQLSQL

SELECT 'Hello World' AS gruss;

SQL has no print: output is result rows. A SELECT without FROM returns one row with the given expressions (not in Oracle, which needs FROM dual).

shBash

#!/usr/bin/env bash
echo "Hello World!"

echo prints text. The shebang line determines that Bash runs the script; then chmod +x hallo.sh and ./hallo.sh.

</>HTML & CSS

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Hello World</title>
</head>
<body>
  <h1>Hello World!</h1>
  <p>My first web page.</p>
</body>
</html>

The minimum of a page: <!DOCTYPE html> activates standards mode, lang helps screen readers and translators, charset ensures correct umlauts and special characters, and the viewport tag ensures correct display on smartphones.

More comparisons

Variables Conditionals Loops Functions Lists and Arrays Dictionaries and Maps Classes and Objects Error Handling Reading Files