Hello, World!

The program which prints “Hello, World!” on the display. This is one of the simplest possible programs for most languages, and is a traditional start for any programming tutorial.

Example for versions Borland C++ Builder 6, g++ 3.4.5, Microsoft Visual C++ 6, Microsoft Visual C++ 9 (2008)

#include <iostream>

int main(void)
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Example for versions Oracle 10g SQL

‘Hello, World!’ string is selected from built-in table dual which is used for queries which don’t need data from real tables.

select 'Hello, World!'
  from dual;

Example for versions gcj 3.4.5, Sun Java 6

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

Example for versions EsCo 0.511 (Brainfuck), Müller's Brainfuck 2.0

There are lots of ways to say “Hello, World!” in Brainfuck. Here is the simplest one: use only one memory cell, and change its value to ASCII-code of each letter in row. Each line of the example prints one letter.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
+++++++++++++++++++++++++++++.
+++++++.
.
+++.
-------------------------------------------------------------------.
------------.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++.
+++.
------.
--------.
-------------------------------------------------------------------.

Example for versions EsCo 0.511 (Brainfuck), Müller's Brainfuck 2.0

In this example we use three memory cells — first for uppercase letters ‘H’ and ‘W’, second for lowercase letters and third for special characters ‘,’, ‘ ‘ and ‘!’ — and three index cells to shorten the notation of ASCII-codes changes. The memory used looks like this:

(index cell 1) (uppercase letters cell) (index cell 2) (lowercase letters cell) (index cell 3) (special characters cell)

++++++[>++++++++++++<-]>.
>++++++++++[>++++++++++<-]>+.
+++++++.
.
+++.
>++++[>+++++++++++<-]>.
<+++[>----<-]>.
<<<<<+++[>+++++<-]>.
>>.
+++.
------.
--------.
>>+.

Example for versions Microsoft SQL Server 2005, MySQL 3.23.57

select 'Hello, World!';

Example for versions Corman Common Lisp 3.0, gcl 2.6.6

When executed in interactive mode, program output looks as follows:

Hello, World!
NIL

First line contains standard output, second — the result of expression evaluation (in this case there is none).

(format t "Hello, World!~%")

Example for versions Squeak 3.10

This example would pop up an information box with “Hello, World!’ as text, and an “Okay” button.

self inform: 'Hello, World!'.

Example for versions Lua 5.0.3

print("Hello, World!")

Example for versions EsCo 0.511 (Brainfuck)

This example is Ook! translation of second Brainfuck example.

Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook. Ook? 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? 
Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! 
Ook. Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook. Ook? 
Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? 
Ook! Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. 
Ook. Ook. Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. 
Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook. Ook. Ook? Ook. Ook? Ook! Ook. 
Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! 
Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! 
Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook. 

Example for versions Microsoft Visual Basic 6

The intended use of Visual Basic is GUI applications development, so creating a simple console application is a non-trivial task itself. This example features:

  • importing required functions from standard library;
  • console creation;
  • getting the handle of console output stream;
  • writing the message to this stream and
  • deallocation of used objects.
Option Explicit

    Declare Function AllocConsole Lib "kernel32" () As Long
    Declare Function FreeConsole Lib "kernel32" () As Long
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
    Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _
           (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _
           nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _
           lpReserved As Any) As Long
    Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) As Long

Private Sub Main()
    'create a console instance
    AllocConsole
    'get handle of console output
    Dim hOut As Long
    hOut = GetStdHandle(-11&)
    'output string to console output
    Dim s As String
    s = "Hello, World!" & vbCrLf
    WriteConsole hOut, ByVal s, Len(s), vbNull, vbNull
    'make a pause to look at the output
    Sleep 2000
    'close the handle and destroy the console
    CloseHandle hOut
    FreeConsole
End Sub

Example for versions QBasic 1.1, QuickBASIC 4.5

PRINT "Hello, World!"

Example for versions EsCo 0.511 (Brainfuck)

This example is Spoon translation of second Brainfuck example. Note that the intended way of coding in Spoon allows writing commands without delimiters, but current version of EsCo requires that commands are space-separated.

1111110010001011111111111101100000110100010100101111111111001000101111111111011000001101
0100101011111110010100010101110010100101111001000101111111111101100000110100010100111110
0100010000000000000011000001101000101001101101101101111100100010111110110000011010001010
0100100010101110010100000000000000000000010100000000000000000000000000010100100101001010

Example for versions Visual Prolog 7.2

Visual Prolog provides automatic project creation, so you have to create a new project, choose “Console” as UI Strategy, navigate to file main.pro and replace its contents with the given code. The code differs from the standard one only in terms stdio::write (to write the message to the console) and programControl::sleep (to pause program execution).

implement main
    open core

constants
    className = "main".
    classVersion = "".

clauses
    classInfo(className, classVersion).

clauses
    run():-
        console::init(),
        stdio::write("Hello, World!"),
        programControl::sleep(1000),
        succeed().
end implement main

goal
    mainExe::run(main::run).

Example for versions Poplog 15.5 (Prolog)

This example doesn’t need any facts or rules to be evaluated. The query is executed in interactive mode, and results in the following output:

Hello, World!
yes

First line is the actual output of write predicate, and second line is the result of query evaluation.

write('Hello, World!'), nl.

Example for versions Python 2.5.2

print "Hello, World!"

Example for versions Free Pascal 2.0.4, gpc 20070904, Turbo Pascal 1.0, Turbo Pascal 2.0, Turbo Pascal 3.0, Turbo Pascal 4.0, Turbo Pascal 5.0, Turbo Pascal 5.5, Turbo Pascal 6.0, Turbo Pascal 7.0

program helloworld;

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

Example for versions ARIBAS 1.53

writeln("Hello, World!");

Example for versions perl 5.8.8

#!/usr/bin/env perl
print "Hello, world!\n";

Example for versions Microsoft Visual Basic .NET 9 (2008)

Module Module1
    Sub Main()
        Console.WriteLine("Hello, World!")
    End Sub
End Module

Example for versions g++ 3.4.5, gcc 3.4.5, gcc 3.4.5 (Objective-C), gcc 4.2.4, Turbo C++ 1.01

#include <stdio.h>

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

Example for versions Microsoft Visual C# 2008

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}

Example for versions gnuplot 4.2.2

#!/usr/bin/env gnuplot
print 'Hello, World!'

Example for versions PHP 5.2.4

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

Example for versions Poplog 15.5 (POP-11)

=> is output operator.

'Hello, World!' =>

Example for versions OCaml 3.11

print_endline is a built-in function defined with the following type:

string -> unit = <func>

This means that it takes 1 string as a parameter, and returns the unit type, ().

let _ = print_endline "Hello World";;

Example for versions D1, D2, gdc 0.24

writef() and writefln() writes to standard output and interpret the first argument as a format string. They are roughly analogous to C’s printf(). writefln() automatically appends a newline. D2 adds write() and writeln() which do not interpret the first argument as a format string. However, they are not available in D1.

module hello;

import std.stdio;

int main()
{
	writefln( "Hello, World!" );
	return 0;
}

Example for versions Perl 6 (alpha)

The comma at the end is optional.

This is also a valid Perl 5.10 program.

say 'Hello, World!';

Example for versions Euphoria v3.1.1, Euphoria v4

The routine puts() writes the second argument (a string) to the device identified by the first argument. There are three predefined devices: 0 is STDIN, 1 is STDOUT, and 2 is STDERR.

puts(1, "Hello, World!\n")

Example for versions Oracle 10g SQL

This example accomplishes the task by means of anonymous PL/SQL block, which uses standard package dbms_output to print the message to standard output.

begin
    dbms_output.put_line('Hello, World!');
end;

Example for versions j602

1!:2 is the dyadic foreign conjunction for writing text, the left argument is the string to be written and the right argument specifies the file number, a file number 2 indicates that the text is to be written to the screen.

Alternatively we can use currying to convert the dyadic write conjunction into a monadic conjunction using the bond (&) operator and assign it to a named print function.

The printf library may also be used to print text to the screen.

'Hello, World!' 1!:2]2

print=: 1!:2&2
print 'Hello, World!'

load 'printf'
'' printf 'Hello, World!\n'

Example for versions REXX

Can’t get much simpler. :-)

#!/usr/bin/rexx
  say 'Hello world!'

Example for versions Algol68g-1.18.0

Note the use of printf with the formatting being described between dollars. eg $gl$ — meaning “g”eneral pattern, then new “l”ine.

( 
  printf(($gl$,"Hello, world!"))
)

Example for versions gfortran 4.5.0, Intel Visual Fortran 11.1

program HelloWorld

print *, 'Hello, World!'

end program HelloWorld

Example for versions SpiderMonkey (Firefox 3.5)

JavaScript uses different commands to output messages depending on what environment is it used in:

  • print: for interpreters with command-line interface prints the message to standard output stream, but when used in web-browser, calls print dialog instead;
  • document.write: when used in web-browser, prints the message to the current document (web-page);
  • console.log: a command for Firebug plugin which prints the message to debug console of the plugin;
  • alert: when used in web-browser, creates a pop-up information window with the message.
print('Hello, World!');

document.write('Hello, World!');

console.log('Hello, World!');

alert('Hello, World!');

Example for versions GHC 6.10.4

module Main where

main = do
    putStrLn "Hello, World!"

Example for versions Furry Paws

~x is constant-value function (denoted with % in Interactive FP). emit is a function which writes its argument to stdout. main is a function which is the first to be invoked when the program is executed.

main = emit.(return ~"Hello, World!\n")

Example for versions gnat 3.4.5

with Ada.Text_IO; 
 
procedure HelloWorld is
begin
  Ada.Text_IO.Put_Line("Hello, World!");
end HelloWorld;

Example for versions Scratch 1.4

Since it’s a graphical language, there is no actual source text, see the print-screen instead. The bat is the sprite of the example, and the script which is associated with it has only one block which makes the sprite “say” the required phrase.

say Hello, World!

Example for versions UCBLogo 6.0

print [Hello, World!]

Example for versions Go gc

package main
import "fmt"

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

Example for versions Scala 2.7.7-final

object HelloWorld {
    def main(args: Array[String]) {
        println("Hello, World!")
    }
}

Example for versions gawk 3.1.6, mawk 1.3.3

The printing is done with BEGIN pattern, i.e., before processing the input.

BEGIN { print "Hello, World!" }

Example for versions Ruby 1.8.5

puts "Hello, World!"

Example for versions S-lang 2.2.2

This example should be executed in slsh interpreter.

message ("Hello, World!");

Example for versions LÖVE 0.6.1

Examples in LÖVE work in the following way: all code is written within standard functions which are called when the application starts. Thus, callback function love.draw is called each time the screen needs to be redrawn. Example code should be placed in file main.lua, which in turn should be placed in project directory, say, hello. After this the code can be run using command love hello, i.e., project directory is used as command line argument.

function love.draw()
    love.graphics.print("Hello World", 10, 20)
end

Example for versions Hanoi Love

This example is a translation of Brainfuck example. All stacks are empty, and all calculations are done in the register. Stack A is used as a source of constant 1: since it’s empty, pop operation on it returns 1. This way, ; and ` operations become “increment register by 1” and “decrement register by 1”, i.e., they are equivalent to + and - Brainfuck commands. "' pushes the contents of the register to standard out, i.e., is equivalent to . in Brainfuck.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;; "'
"'
;;; "'
``````````````````````````````````````````````````````````````````` "'
```````````` "'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;;;;;;;;;;;;;;;;;;; "'
;;; "'
`````` "'
```````` "'
``````````````````````````````````````````````````````````````````` "'