Un programma "Hello, world!" (anglese pro "Hallo, mundo!") frequentemente es utilisate pro facer un demonstration rapide de un linguage de programmation, per exemplo, in capitulos introductori de manuales e cursos. Iste typo de programma es multo simple, e solmente exhibi le message "Hello, world!" super le schermo del usator. Pro le majoritate de linguages, un programma "Hello World" es un del plus simple programmas possibile, ben que alcun exemplos es multo complexe, in particular illos que debe exhibir le message in un ambiente graphic (GUI).

Hello World
subclasse de: demo program[*]


Commons: Hello World

Un programma "hello, world" pote esser un prova utile pro indicar que le compilator, ambiente de disveloppamento, e ambiente de tempore de execution (run-time) es installate correctemente. Quando on vole provar un nove collection de utensiles pro programmation, frequentemente il es melior provar con un programma simplissime (sed un que clarmente indica su successo).

Ben que parve programmas de prova ha existite ab le invention de computatores programmabile, le tradition de usar le phrase "Hello, world!" como le indication de successo esseva establite per un programma exemplari in le libro The C Programming Language ("le linguage de programmation C") per Brian Kernighan e Dennis Ritchie. Le programma exemplari de iste libro imprime "hello, world".

Un collection de programmas "hello, world" scribite in varie linguages de programmation pote servir como un "Petra de Rosetta" pro adjutar in apprender e comparar le linguages.

Ecce alcun exemplos de varie linguages:

Ambiente textual

modificar
   with Ada.Text_Io; use Ada.Text_Io;
   procedure Hello is
   begin
      Put_Line ("Hello, world!");
   end Hello;

linguage de montage (assembly) (UCP x86, MS-DOS, syntaxe TASM)

modificar
   MODEL SMALL
   IDEAL
   STACK 100H
   DATASEG
       HW      DB      'Hello, world!$'
   CODESEG
       MOV AX, @data
       MOV DS, AX
       MOV DX, OFFSET HW
       MOV AH, 09H
       INT 21H
       MOV AX, 4C00H
       INT 21H
   END
   BEGIN { print "Hello, world!" }
   Traditional - BASIC non structurate
   10 PRINT "Hello, world!"
   20 END
   Versiones plus moderne - BASIC structurate
   print "Hello, world!"
   GET "LIBHDR"

   LET START () BE
   $(
       WRITES ("Hello, world!*N")
   $)
   #include <stdio.h>
    
   int main(void)
   {
       printf("Hello, world!\n");
       return 0;
   }
   #include <iostream>
    
   int main()
   {
       std::cout << "Hello, world!" << std::endl;
   }
   class AppHalloMundo {
     public static void Main() {
       System.Console.WriteLine("Hello, world!");
     }
   }
   module hallo
   Start :: String
   Start = "Hello, world"
   IDENTIFICATION DIVISION.
   PROGRAM-ID.     HALLO-MUNDO.
   ENVIRONMENT DIVISION.
   DATA DIVISION.
   PROCEDURE DIVISION.
   DISPLAY "Hello, world!".
   STOP RUN.
   (format t "Hello world!~%")
   class HALLO_MUNDO
   creation
       make
   feature
       make is
       local
               io:BASIC_IO
       do
               !!io
               io.put_string("%N Hello, world!")
       end -- make
   end -- class HALLO_MUNDO
       -module(hallo).
       -export([hallo_mundo/0]).
       hallo_mundo() -> io:fwrite("Hello, world!\n").
   ." Hello, world!" CR
      PROGRAM HALLO
      WRITE(*,10)
   10 FORMAT('Hello, world!')
      STOP
      END
   module HalloMundo (main) where
   main = putStrLn "Hello World"
   ON ENTER {
       "Hello, " "World!" & SAY
   }
   public class Hello {
       public static void main(String[] args) {
           System.out.println("Hello, world!");
       }
   }
   print "Hello, world!"
    TERM    EQU    19          numero del "MIX console device"
            ORIG   1000        adresse initial
    START   OUT    MSG(TERM)   expelle datos al adresse MSG
            HLT                stoppa execution
    MSG     ALF    "MIXAL"
            ALF    " HELL"
            ALF    "O WOR"
            ALF    "LD   "
            END    START       fin del programma

Linguage de lot de MS-DOS

modificar
   @echo off
   echo Hello, world!
   let _ =
      print_endline "Hello world!";;
   PROC hallo:
     PRINT "Hello, World"
   ENDP
   program Hallo(output);
   begin
       writeln('Hello, world!')
   end.
   print "Hello, world!\n";
   <?php
       print("Hello, world!");
   ?>
   #!/usr/local/bin/pike
   int main() {
       write("Hello, world!\n");
       return 0;
   }
   Prova: procedure options(main);
      declare Mi_Vector char(20) varying initialize('Hello, world!');
      put skip list(Mi_Vector);
   end Prova;
   print "Hello, world!"
   say "Hello, world!"
   print "Hello, world!\n"
   K) PROGRAM DRUKUJE NAPIS HELLO WORLD
       LINIA
       TEKST:
       HELLO WORLD
       KONIEC
   (display "Hello, world!")
   (newline)

sed (require al minus un linea de input (de stdin))

modificar
   sed -ne '1s/.*/Hello, world!/p'
   $ include "seed7_05.s7i";

   const proc: main is func
     begin
       writeln("Hello, world!");
     end func;
   Transcript show: 'Hello, world!'
   print "Hello, world!\n";
       OUTPUT = "Hello, world!"
   END
   create table HALLO (TEXTO char(15));
   insert into HALLO (TEXTO) values ('Hello, world!');
   select TEXTO from HALLO;
   drop table HALLO;
   sub main
   print "Hello, World"
   end sub
   puts "Hello, world!"
   :Disp "Hello, world!"
   put "Hello, world!"
   echo 'Hello, world!'
   Algorithmo Hallo es:
       sia s:="Hello, world";
       imprime s;
   fin-Hallo

Ambiente graphic — como applicationes traditional

modificar
   MsgBox "Hello, world!"

C++ 'bindings' pro GTK toolkit de infographia

modificar
   #include <iostream>
   #include <gtkmm/main.h>
   #include <gtkmm/button.h>
   #include <gtkmm/window.h>
   using namespace std;
   class HalloMundo : public Gtk::Window {
   public:
     HalloMundo();
     virtual ~HalloMundo();
   protected:
     Gtk::Button m_button;
     virtual void on_button_clicked();
   };
   HalloMundo::HalloMundo()
   : m_button("Hello, world!") {
       set_border_width(10);
       m_button.signal_clicked().connect(SigC::slot(*this,
                                         &HalloMundo::on_button_clicked));
       add(m_button);
       m_button.show();
   }
   HalloMundo::~HalloMundo() {}
   void HalloMundo::on_button_clicked() {
       cout << "Hello, world!" << endl;
   }
   int main (int argc, char *argv[]) {
       Gtk::Main kit(argc, argv);
       HalloMundo halloamico;
       Gtk::Main::run(halloamico);
       return 0;
   }
   #include <qapplication.h>
   #include <qpushbutton.h>
   #include <qwidget.h>
   #include <iostream>
   class HalloMundo : public QWidget
   {
       Q_OBJECT
   public:
       HalloMundo();
       virtual ~HalloMundo();
   public slots:
       void handleButtonClicked();
       QPushButton *mPushButton;
   };
   HalloMundo::HalloMundo() :
       QWidget(),
       mPushButton(new QPushButton("Hello, World!", this))
   {
       connect(mPushButton, SIGNAL(clicked()), this, SLOT(handleButtonClicked()));
   }
   HalloMundo::~HalloMundo() {}
   void HalloMundo::handleButtonClicked()
   {
       std::cout << "Hello, World!" << std::endl;
   }
   int main(int argc, char *argv[])
   {
       QApplication app(argc, argv);
       HalloMundo halloAmico;
       app.setMainWidget(&halloAmico);
       halloAmico.show();
       return app.exec();
   }

(iste codice es in anglese) :-)

   #include <windows.h>
   LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
   char szClassName[] = "MainWnd";
   HINSTANCE hInstance;
   int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
   {
     HWND hwnd;
     MSG msg;
     WNDCLASSEX wincl;
     hInstance = hInst;

     wincl.cbSize = sizeof(WNDCLASSEX);
     wincl.cbClsExtra = 0;
     wincl.cbWndExtra = 0;
     wincl.style = 0;
     wincl.hInstance = hInstance;
     wincl.lpszClassName = szClassName;
     wincl.lpszMenuName = NULL; //No menu
     wincl.lpfnWndProc = WindowProcedure;
     wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //Color of the window
     wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //EXE icon
     wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Small program icon
     wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor

     if (!RegisterClassEx(&wincl))
           return 0;
     hwnd = CreateWindowEx(0, //No extended window styles
           szClassName, //Class name
           "", //Window caption
           WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
           CW_USEDEFAULT, CW_USEDEFAULT, //Let Windows decide the left and top positions of the window
           120, 50, //Width and height of the window,
           NULL, NULL, hInstance, NULL);
     //Make the window visible on the screen
     ShowWindow(hwnd, nCmdShow);

     //Run the message loop
     while (GetMessage(&msg, NULL, 0, 0))
     {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
     }
     return msg.wParam;
   }
   LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   {
     PAINTSTRUCT ps;
     HDC hdc;
     switch (message)
     {
     case WM_PAINT:
           hdc = BeginPaint(hwnd, &ps);
           TextOut(hdc, 15, 3, "Hello, world!", 13);
           EndPaint(hwnd, &ps);
           break;
     case WM_DESTROY:
           PostQuitMessage(0);
           break;
     default:
           return DefWindowProc(hwnd, message, wParam, lParam);
     }
     return 0;
   }
   import java.awt.*;
   import java.awt.event.*;
   public class QuadroDeSalutation extends Frame {
     QuadroDeSalutation(String titulo) {
       super(titulo);
     }
     public void paint(Graphics g) {
       super.paint(g);
       java.awt.Insets ins = this.getInsets();
       g.drawString("Hello, world!", ins.left + 25, ins.top + 25);
     }
     public static void main(String args [])
     {
       QuadroDeSalutation qua = new QuadroDeSalutation("Hello");
       qua.addWindowListener(
         new WindowAdapter() {
           public void windowClosing(WindowEvent e)
           {
             System.exit( 0 );
           }
         }
       );
       qua.setResizable(true);
       qua.setSize(500, 100);
       qua.setVisible(true);
     }
   }


Ambiente graphic basate super navigator del web

modificar
Le applets Java es appellate de archivos HTML.
   <html>
   <head>
   <title>Hallo Mundo</title>
   </head>
   <body>

Mi programma "hello world" dice:

   <applet code="HalloMundo.class" width="600" height="100">
   </applet>
   </body>
   </html>
   import java.applet.*;
   import java.awt.*;
   public class HalloMundo extends Applet {
     public void paint(Graphics g) {
       g.drawString("Hello, world!", 100, 50);
     }
   }
JavaScript (o ECMAScript) es un linguage de programmation de scripts incastrate in files HTML. Pro probar iste programma simplemente pone le codice sequente intra le elemento <head> de qualcunque file HTML.
    <script language="javascript">
    function halloMundo()
    {
        alert("Hello, world!");
    }
    </script>
    <a href="javascript:this.location()"
     onclick="javascript:halloMundo();">Programma "hello world"</a>
Un methodo plus facile usa le JavaScript in un maniera implicite, e appella le function reservate alert. Copia e colla le sequente codice intro le elemento <body> de un file HTML.
    <a href="#" onclick="alert('Hello, world!')">Programma "hello world"</a>
Un methodo ja plus facile usa le protocollo virtual 'javascript' (supportate per le majoritate de navigatores popular) pro executar le codice. Simplemente pone le linea sequente a in le campo de adresse de vostre navigator:
    javascript:alert('Hello, world!')
   <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <box align="center">
   <label value="Hello, world!" />
   </box>
   </window>

Formatos de documentos

modificar
Le serie sequente de characteres (exprimite ci in notation hexadecimal):
    48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A
   <html>
   <head>
   <title>Hallo, Mundo!</title>
   </head>
   <body>
   <p>Hello, world!</p>
   </body>
   </html>
   /font /Courier findfont 24 scalefont
   font setfont
   100 100 moveto
   (Hello world!) show
   showpage
   \font\HW=cmr10 scaled 3000
   \leftline{\HW Hello world}
   \bye

Ligamines externe

modificar