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 clisp 2.47, 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, Free Pascal 2.2.0, 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 gmcs 2.0.1, 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!'
Rexx Language Association
Open Object Rexx
IBM logo
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, gnat 4.3.2
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!
"Hello, World!" example in Scratch
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 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.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;; "'
"'
;;; "'
``````````````````````````````````````````````````````````````````` "'
```````````` "'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "'
;;;;;;;;;;;;;;;;;;;;;;;; "'
;;; "'
`````` "'
```````` "'
``````````````````````````````````````````````````````````````````` "'
Example for versions Sanscript 2.2
Sanscript is a fully visual programming language, so no source code is available. See screenshot instead.
The flowgram (Sanscript equivalent of program) for this example consists of two functions: constant “Hello, World!” and function “Display Message”. Once the flowgram runs, the constant function produces the message on its outlet. An arrow link connects this outlet to inlet of “Display Message” function, so it creates a pop-up window with this message.
"Hello, World!" example in Sanscript
Example for versions Müller's Brainfuck 2.0
This example is a Brainloller translation of this example. Since Brainloller is a fully graphical language, no source code is available, see screenshots instead.
"Hello, World!" example in Brainloller
"Hello, World!" example in Brainloller (10x scale)
Example for versions Müller's Brainfuck 2.0
The program itself is too large, so it is given in shortened way. This example is a translation of second Brainfuck example.
A string of
118813560323277653191662803047326384277538345326678115429767453537450
292866914557015460910172702778221910307831726746340921263104469613504
59705393993241449826477775919360678577399889787062444 zeroes (approximately 1*10^190).
Example for versions Ellsässer's HQ9+ 0.8
In this language any code which contains H command and doesn’t contain Q or 9 commands outputs “Hello, World!”.
H
Example for versions Simply Scala
In Simply Scala you can evaluate expressions without framing them as objects.
println("Hello, World!")
Example for versions Roco 20071014
This code uses only main coroutine; it outputs the message character by character, using their ASCII codes, and stops.
cout 72
cout 101
cout 108
cout 108
cout 111
cout 44
cout 32
cout 87
cout 111
cout 114
cout 108
cout 100
cout 33
ac
Example for versions Bash 3.0
This example demonstrates script declaration line, comment, variables and difference between single and double quotes. This is likely enough for Hello. As it should be in bash, message can be configured through parameters.
#!/bin/bash
# Prints "Hello world" message in Bash, Unix shell.
MESSAGE='hello'
TARGET='world'
echo "$MESSAGE $TARGET"
Example for versions LabVIEW 10.0
G/LabVIEW is a fully visual programming language, so no source code is available. See screenshot instead.
The block diagram (LabVIEW equivalent of program) for this example consists of only one node — “Display Message to User”, with pre-set message “Hello, World!”.
To create this example, create a new project and a new VI within it. Switch to Block Diagram of the new VI. Navigate to Functions -> Programming -> “Dialog and User Interface”, choose “Display Message To User” control and place it onto the Block Diagram area. Once it’s placed, a configuration dialog will appear; enter “Hello, World!” as the message to display. Save the project and press “Run” to get a pop-up message box. The screenshot shows both the block diagram and the result of its execution.
"Hello, World!" example in G/LabVIEW
Example for versions fsharp 2.0.0
printfn "Hello, World!"