"Hello, World!" program
A "Hello, World!" program is generally a computer program that outputs or displays the message "Hello, World!". This program is very simple to write in many programming languages, and is often used to illustrate a language's basic syntax. "Hello, World!" programs are often the first a student learns to write in a given language, and they can also be used as a sanity test to ensure computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.

History

While small test programs have existed since the development of programmable computers, the tradition of using the phrase "Hello, World!" as a test message was influenced by an example program in the seminal 1978 book The C Programming Language. The example program in that book prints "", and was inherited from a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial:

main( ) {
        printf("hello, world");
}

In the above example, the  function defines where the program should start executing. The function body consists of a single statement, a call to the  function, which stands for "print formatted". This function will cause the program to output whatever is passed to it as the parameter, in this case the string .

The C language version was preceded by Kernighan's own 1972 A Tutorial Introduction to the Language B, where the first known version of the program is found in an example used to illustrate external variables:
main( ) {
    extern a, b, c;
    putchar(a); putchar(b); putchar(c); putchar('!*n');
}
 
a 'hell';
b 'o, w';
c 'orld';

The program also prints  on the terminal, including a newline character. The phrase is divided into multiple variables because in B, a character constant is limited to four ASCII characters. The previous example in the tutorial printed  on the terminal, and the phrase  was introduced as a slightly longer greeting that required several character constants for its expression.

The Jargon File claims that "Hello, World!" originated instead with BCPL (1967). This claim is supposedly supported by the archived notes of the inventors of BCPL, Brian Kernighan at Princeton and Martin Richards at Cambridge. The phrase predated by over a decade its usage in computing; as early as the 1950s, it was the catchphrase of radio disc jockey William B. Williams.

Variations

"Hello, World!" programs vary in complexity between different languages. In some languages, particularly scripting languages, the "Hello, World!" program can be written  as a single statement, while in others (particularly many low-level languages) there can be many more statements required. For example, in Python, to print the string  followed by a newline, one only needs to write print("Hello, World!"). In contrast, the equivalent code in C++ requires the import of the input/output software library, the manual declaration of an entry point, and the explicit instruction that the output string should be sent to the standard output stream. Generally, programming languages that give the programmer more control over the machine will result in more complex "Hello, World" programs.

The phrase "Hello World!" has seen various deviations in punctuation and casing, such as the presence of the comma and exclamation mark, and the capitalization of the leading H and W. Some devices limit the format to specific variations, such as all-capitalized versions on systems that support only capital letters, while some esoteric programming languages may have to print a slightly modified string. For example, the first non-trivial Malbolge program printed "Hello world", this having been determined to be good enough. Other human languages have been used as the output; for example, a tutorial for the Go programming language outputted both English and Chinese or Japanese characters, demonstrating the programming language's built-in Unicode support.

Some languages change the functionality of the "Hello, World!" program while maintaining the spirit of demonstrating a simple example. Functional programming languages, such as Lisp, ML, and Haskell, tend to substitute a factorial program for "Hello, World!", as functional programming emphasizes recursive techniques, whereas the original examples emphasize I/O, which violates the spirit of pure functional programming by producing side effects. Languages otherwise capable of printing "Hello, World!" (Assembly, C, VHDL) may also be used in embedded systems, where text output is either difficult (requiring additional components or communication with another computer) or nonexistent. For devices such as microcontrollers, field-programmable gate arrays, and CPLDs, "Hello, World!" may thus be substituted with a blinking LED, which demonstrates timing and interaction between components.

The Debian and Ubuntu Linux distributions provide the "Hello, World!" program through their software package manager systems, which can be invoked with the command . It serves as a sanity check and a simple example of installing a software package. For developers, it provides an example of creating a .deb package, either traditionally or using debhelper, and the version of  used, GNU Hello, serves as an example of writing a GNU program.

Variations of the "Hello, World!" program that produce a graphical output (as opposed to text output) have also been shown. Sun demonstrated a "Hello, World!" program in Java based on scalable vector graphics, and the XL programming language features a spinning Earth "Hello, World!" using 3D computer graphics. Mark Guzdial and Elliot Soloway have suggested that the "hello, world" test message may be outdated now that graphics and sound can be manipulated as easily as text.

Time to Hello World
"Time to hello world" (TTHW) is the time it takes to author a "Hello, World!" program in a given programming language. This is one measure of a programming language's ease-of-use; since the program is meant as an introduction for people unfamiliar with the language, a more complex "Hello, World!" program may indicate that the programming language is less approachable. The concept has been extended beyond programming languages to APIs, as a measure of how simple it is for a new developer to get a basic example working; a shorter time indicates an easier API for developers to adopt.

Examples

Ballerina 
import ballerina/io;

public function main() {
    io:println("Hello, World!");
}

BASIC 
10 PRINT "Hello, World!"

Batch file 
@echo off
echo Hello, World!

Bash 
echo "Hello, World!"

C 
#include <stdio.h>

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

C++ 
#include <iostream>

int main() 
{
  std::cout << "Hello, World!\n";
  return 0;
}
C++23 version:
#include <format>

int main() 
{
  std::print("Hello, World!\n");
  return 0;
}

C# 
Console.WriteLine("Hello, World!");

COBOL 
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
* simple hello world program
PROCEDURE DIVISION.
    DISPLAY 'Hello, World!'.
    STOP RUN.

Clojure 
(println "Hello, World!")

D 
import std.stdio;
void main()
{
    writeln("Hello, World!");
}

Dart 
void main() {
  print('Hello, World!');
}

Elixir 
IO.puts("Hello, World!")

Ezhil 
பதிப்பி "உலகே வணக்கம்"
பதிப்பி "Hello, World!"
exit()

Fortran 
program Hello
  print *, "Hello, World!"
end program Hello

Go 
package main
import "fmt"

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

Haskell 
main :: IO ()
main = putStrLn "Hello, World!"

Java 
class Main {
 public static void main() {
    System.out.println("Hello, World!");
  }
}

JavaScript 

// For HTML Document
document.write("Hello, World!");

// For Browser Console
console.log("Hello, World!");

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

Logo 

 print [Hello, World!]

Lua 
print("Hello, World!")

mq 
function hello(r) {
    r.return(200, "Hello, World!");
}

export default {hello};

Objective-C 
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, World!");
    }
    return 0;
}

OCaml 
print_endline "Hello, World!"

Pascal 
program Hello;
begin
  writeln ('Hello, World!');
end.

Perl 
print "Hello, World!\n";

PHP 
<?php
  echo 'Hello, World!';
?>If purely using PHP:<?php
  echo 'Hello, world!';

PowerShell 
'Hello, World!'

Prolog 
main() :- write("Hello, World!"), nl.

Python 
print("Hello, World!")

Ruby 
puts "Hello, World!"

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

Standard ML 
print "Hello, World!\n"

Swift 
print("Hello, World!")

TI-BASIC 
:Disp "HELLO, WORLD!"

Zig 
const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, World!", .{});
}

See also 

 
 "99 Bottles of Beer" as used in computer science
 Foobar
 Bad Apple!! (graphic equivalent to "Hello, World!" for old hardware)
 Java Pet Store
 Just another Perl hacker
 List of basic computer science topics
 Trabb Pardo-Knuth algorithm

References

External links 

 
 
 
 

Test items in computer languages
Computer programming folklore
Articles with example code