Certains des programmes imprimant ces mots sont étonnamment complexes, particulièrement dans un contexte d'interface graphique. D'autres sont très simples, particulièrement ceux qui utilisent un interpréteur de ligne de commande pour afficher le résultat. Dans plusieurs systèmes embarqués, le texte peut être envoyé sur une ou deux lignes d'un afficheur LCD (ou dans d'autres systèmes, une simple DEL peut se substituer à un hello world).
Histoire
Alors que les petits programmes de test existaient depuis le début de la programmation, la tradition d'utiliser hello world comme message de test a été initiée par le livre The C Programming Language de Brian Kernighan et Dennis Ritchie. Le premier exemple de ce livre affiche hello, world (sans majuscule ni point final, mais avec une virgule et un retour à la ligne final). Le premier hello world dont Ritchie et Kernighan se souviennent provient d'un manuel d'apprentissage du langage B écrit par Kernighan.
Au XXI siècle, les programmes affichent plus souvent Hello world! comme une phrase, avec majuscule et point d'exclamation final.
var champ:TextField = new TextField(); champ.text = "Hello World !"; this.addChild(champ);
ou en alerte :
Alert.show("Hello world !");
Ada
with Ada.Text_IO; use Ada.Text_IO; procedure Bonjour is begin -- Bonjour Put("Hello world!"); end Bonjour;
Alma
Hello world!
AmigaE
PROC main() WriteF('Hello world!') ENDPROC
APL
'Hello world!'
AppleScript
display dialog "Hello world!"
ASP et ASP.NET
<% Response.Write("Hello World") %>
AspectJ
Main.java: public class Main { public static void main(String[] args){ } } HelloWorld.aj: public aspect HelloWorld { pointcut mainCall() : call(public static void *.main(String[] args)); before() : mainCall() { System.out.println( "Hello world!" ); } }
Assembleur de Bytecode Java
.class public Hello .super java/lang/Object ; spécification du constructeur par défaut .method public (); ; pousse la référence à l'objet courant sur la pile aload_0 ; appel statiquement lié aux constructeurs de la classe de base invokespecial java/lang/Object/()V return .end method .method public static main([java/lang/String;)V .limit stack 2 ; pousse la réf. à l'objet statique out de la classe System sur la pile getstatic java/lang/System/out Ljava/io/PrintStream ; pousse la chaîne de caractère sur la pile ldc "Hello world!" ; appel polymorphe invokevirtual java/io/PrintStream/println(Ljava.lang.String;)V return .end method
Assembleur x86 sous DOS
cseg segment assume cs:cseg, ds:cseg org 100h main proc jmp debut mess db 'Hello world!$' debut: mov dx, offset mess mov ah, 9 int 21h ret main endp cseg ends end main
Assembleur x86, écrit pour l'assembleur TASM sous DOS
.model small .stack 100h .data bonjour db "Hello world!$" .code main proc mov AX,@data mov DS, AX mov DX, offset bonjour mov AX,0900h int 21h mov AX,4C00h int 21h main endp end main
Assembleur x86, sous Linux, écrit pour l'assembleur NASM
section .data helloMsg: db 'Hello world!',10 helloSize: equ $-helloMsg section .text global _start _start: mov eax,4 ; Appel système "write" (sys_write) mov ebx,1 ; File descriptor, 1 pour STDOUT (sortie standard) mov ecx, helloMsg ; Adresse de la chaîne a afficher mov edx, helloSize ; Taille de la chaîne int 80h ; Execution de l'appel système ; Sortie du programme mov eax,1 ; Appel système "exit" mov ebx,0 ; Code de retour int 80h
Assembleur x86 écrit pour l'assembleur FASM
org 100h mov dx, message mov ah, 09h int 21h ; les quatre lignes suivantes servent à attendre qu'une touche soit frappée avant de quitter le programme normalement ; elles peuvent donc être exclues du programme, à ceci près que la visualisation du résultat sera impossible, la fenêtre de console ; se refermant trop vite xor ah, ah int 16h mov ax, 4c00h int 21h message db "Hello world!$"
Assembleur x86 écrit pour l'assembleur MASM
.386 .MODEL flat, stdcall OPTION CASEMAP: none Include kernel32.inc Include masm32.inc Includelib kernel32.lib Includelib masm32.lib .data HelloWorld db "Hello World!" , 0 .data? WaitBufer db 10 dup(?) .code Start : invoke StdOut, addr HelloWorld invoke StdIn, addr WaitBufer, 1 invoke ExitProcess, 0 End Start
Awk
#!/usr/bin/awk -f BEGIN { print "Hello world!" }
BASIC
10 PRINT "Hello world!" 20 END 'A noter que le END n est pas nécessaire
Les étiquettes (numéros devant les lignes) ne sont plus nécessaires dans les versions modernes (BBC BASIC for Windows, Quick Basic, Turbo Basic, QBasic, Visual Basic...). Elles ne sont plus utilisées que pour les instructions de contrôle de flux (les boucles et les sauts, notamment le GOTO et le GOSUB).
Bash
#!/bin/bash echo 'Hello world'
BCPL
GET "LIBHDR" LET START () BE $( WRITES ("Hello world!*N") $)
Befunge
<q_,#! #:<"Hello world!"a
Brainfuck
préparation[>+>>+>+<<<<-] écrit "Hello " >. >+. +. . +. >. écrit "World!" et passe à la ligne <<+++++++++++++. >. +. ------. --------. >+. >.
C
#include <stdio.h> int main()/* ou int argc, char *argv[] */ { printf("Hello world!\n"); return 0; }
C (sous Microsoft Windows, API Win32)
#include <windows.h> int WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { MessageBox( NULL, TEXT ("Hello world!\n"), TEXT (""), MB_OK ); return 0; }
C (sur Sony PSP)
#include <pspkernel.h> #include <pspdebug.h> PSP_MODULE_INFO("Hello World", 0, 1, 0); #define printf pspDebugScreenPrintf /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) sceKernelStartThread(thid, 0, 0); return thid; } int main() { pspDebugScreenInit(); SetupCallbacks(); printf("Hello, World"); sceKernelSleepThread(); return 0; }
C# (en Console)
using System; public class HelloWorld { public static void Main () { Console.WriteLine("Hello world!"); } }
C# (Application Windows)
using System.Windows.Forms; public class HelloWorld { public static void Main() { MessageBox.Show("Hello world!"); } }
Livre : HelloWorld Paragraphe : Affichage Les actions : "Hello, World !" !
Lisaac
Section Header + name := HELLO_WORLD; Section Public - main <- ( "Hello world !".println; );
Lisp
(write-line "Hello World!")
Logo
print [Hello world!]
ou
pr [Hello world!]
en mswlogo seulement
messagebox [Hi] [Hello world!]
LOLCODE
HAI CAN HAS STDIO? VISIBLE "HAI WORLD!" KTHXBYE
Lua
print("Hello world!")
Lua sur PSP
red = Color.new(255, 0, 0) --declaration de la couleur rouge while true do --commencement de la boucle screen:clear()-- efface l'ecran screen:print(00,10,"Hello World", red)-- affiche le texte "Hello World" en position {0;10} en rouge screen.waitVblankStart()-- attend la synchronisation verticale de l'écran screen.flip()-- actualise l'ecran end --fin de la boucle
MODULE Hello; FROM Terminal2 IMPORT WriteLn, WriteString; BEGIN WriteString("Hello world!"); WriteLn; END Hello.
MS-DOS batch
@echo Hello world! pause
MUF
: main me @ "Hello world!" notify ;
MXML
NSIS
Name "Hello, world" OutFile "helloworld.exe" Section .main ; En tant qu'action courante DetailPrint "Hello, world !" ; Sur une boîte de dialogue MessageBox MB_OK "Hello, world !" SectionEnd
Objective C
#import <Foundation/Foundation.h> int main () { NSLog(@"Hello world!"); return 0; }
Objective Caml
print_endline "Hello world"
Octave
#!/usr/bin/octave disp("hello world")
Ook
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook! Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook? Ook! Ook.
hello: procedure options(main); display ('Hello world!'); /* Ou, variante : put skip list ('Hello world!'); */ end hello;
PL/SQL
SET SERVEROUTPUT ON BEGIN DBMS_OUTPUT.PUT_LINE('Hello world!'); END;
PL/pgSQL
CREATE FUNCTION hello_world() RETURNS VOID AS BEGINRAISENOTICE′HelloWorld′;ENDBEGIN RAISE NOTICE 'Hello World'; ENDBEGINRAISENOTICE′HelloWorld′;END LANGUAGE 'plpgsql' VOLATILE;
POP-11
'Hello world!' =>
POV-Ray
#include "colors.inc" camera { location <3, 1, -10> look_at <3,0,0> } light_source { <500,500,-1000> White } text { ttf "timrom.ttf" "Hello world!" 1, 0 pigment { White } }
Ce qui donnera
PostScript
%!PS 100 /Helvetica findfont exch scalefont setfont 10 300 moveto (Hello, world !) show showpage
PROC (langage de commande Pick)
001 PQ 002 C Affiche 'Hello, world !' à l'écran 003 OHello, world ! 004 X
Prolog
:- write('Hello world!'), nl.
Pseudo-code
output Hello world!
PureBasic
OpenConsole() PrintN("Hello World!") ;ou en mode fenêtré MessageRequester("Titre","Hello World")
program Hello_World; {titre du programme, facultatif} begin writeln('Hello World'); {affiche le message et saute une ligne} readln; {Sert de pause, facultatif} end.
Turing
put "Hello world!"
TSQL
Declare @Output varchar(16) Set @Output='Hello world!' Select @Output
ou, variation plus simple:
Select 'Hello world!' Print 'Hello world!'
TI-59
000 69 OP 001 00 00 efface la ligne 002 02 2 003 03 3 H 004 01 1 005 07 7 E 006 69 OP 007 01 01 dans la zone de gauche 008 02 2 009 07 7 L 010 02 2 011 07 7 L 012 03 3 013 02 2 O 014 00 0 015 00 0 espace 016 04 4 017 03 3 W 018 69 OP 019 02 02 dans la zone milieu-gauche 020 03 3 021 02 2 O 022 03 3 023 05 5 R 024 02 2 025 07 7 L 026 01 1 027 06 6 D 028 07 7 029 03 3 ! 030 69 OP 031 03 03 dans la zone milieu-droit 032 69 OP 033 05 05 imprime la ligne 034 91 R/S arrêt du programme
public class HelloWorld { public static int main(string[] args) { print("Hello world!"); return 0; } }
Verilog
module main; initial begin $display("Hello, world"); $finish ; end endmodule
VHDL
use std.textio.all; ENTITY hello IS END ENTITY hello; ARCHITECTURE Wiki OF hello IS CONSTANT message : string := "hello world"; BEGIN PROCESS variable L: line; BEGIN write(L, message); writeline(output, L); wait; END PROCESS; END ARCHITECTURE Wiki;
VBA (Visual Basic for Application)
Sub Main MsgBox "Hello world!" End Sub
Visual Basic .NET (Application Console)
Imports System Public Shared Sub Main() Console.WriteLine("Hello World!") End Sub
Visual Basic .NET (Application Windows Forms)
Imports System.Windows.Forms Public Shared Sub Main() MessageBox.Show("Hello World!") End Sub
Le .Show n'est pas obligatoire mais les parenthèses oui