Hello World

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 qui debe exhibir le message in un ambiente graphic (GUI).

Hello World
subclasse de: demo program[*]
Hola Mundo AppleScript.png


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 qui 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 textualModificar

AdaModificar

   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

AWKModificar

   BEGIN { print "Hello, world!" }

BASICModificar

   Traditional - BASIC non structurate
   10 PRINT "Hello, world!"
   20 END
   Versiones plus moderne - BASIC structurate
   print "Hello, world!"

BCPLModificar

   GET "LIBHDR"

   LET START () BE
   $(
       WRITES ("Hello, world!*N")
   $)

CModificar

   #include <stdio.h>
    
   int main(void)
   {
       printf("Hello, world!\n");
       return 0;
   }

C++Modificar

   #include <iostream>
    
   int main()
   {
       std::cout << "Hello, world!" << std::endl;
   }

C#Modificar

   class AppHalloMundo {
     public static void Main() {
       System.Console.WriteLine("Hello, world!");
     }
   }

CleanModificar

   module hallo
   Start :: String
   Start = "Hello, world"

COBOLModificar

   IDENTIFICATION DIVISION.
   PROGRAM-ID.     HALLO-MUNDO.
   ENVIRONMENT DIVISION.
   DATA DIVISION.
   PROCEDURE DIVISION.
   DISPLAY "Hello, world!".
   STOP RUN.

Common LispModificar

   (format t "Hello world!~%")

EiffelModificar

   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

ErlangModificar

       -module(hallo).
       -export([hallo_mundo/0]).
       hallo_mundo() -> io:fwrite("Hello, world!\n").

ForthModificar

   ." Hello, world!" CR

FortranModificar

      PROGRAM HALLO
      WRITE(*,10)
   10 FORMAT('Hello, world!')
      STOP
      END

HaskellModificar

   module HalloMundo (main) where
   main = putStrLn "Hello World"

IptscraeModificar

   ON ENTER {
       "Hello, " "World!" & SAY
   }

JavaModificar

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

LuaModificar

   print "Hello, world!"

MIXALModificar

    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-DOSModificar

   @echo off
   echo Hello, world!

OCamlModificar

   let _ =
      print_endline "Hello world!";;

OPLModificar

   PROC hallo:
     PRINT "Hello, World"
   ENDP

PascalModificar

   program Hallo(output);
   begin
       writeln('Hello, world!')
   end.

PerlModificar

   print "Hello, world!\n";

PHPModificar

   <?php
       print("Hello, world!");
   ?>

PikeModificar

   #!/usr/local/bin/pike
   int main() {
       write("Hello, world!\n");
       return 0;
   }

PL/IModificar

   Prova: procedure options(main);
      declare Mi_Vector char(20) varying initialize('Hello, world!');
      put skip list(Mi_Vector);
   end Prova;

PythonModificar

   print "Hello, world!"

REXXModificar

   say "Hello, world!"

RubyModificar

   print "Hello, world!\n"

SAKOModificar

   K) PROGRAM DRUKUJE NAPIS HELLO WORLD
       LINIA
       TEKST:
       HELLO WORLD
       KONIEC

SchemeModificar

   (display "Hello, world!")
   (newline)

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

   sed -ne '1s/.*/Hello, world!/p'

Seed7Modificar

   $ include "seed7_05.s7i";

   const proc: main is func
     begin
       writeln("Hello, world!");
     end func;

SmalltalkModificar

   Transcript show: 'Hello, world!'

SMLModificar

   print "Hello, world!\n";

SNOBOLModificar

       OUTPUT = "Hello, world!"
   END

SQLModificar

   create table HALLO (TEXTO char(15));
   insert into HALLO (TEXTO) values ('Hello, world!');
   select TEXTO from HALLO;
   drop table HALLO;

StarOffice BasicModificar

   sub main
   print "Hello, World"
   end sub

TclModificar

   puts "Hello, world!"

TI-BASICModificar

   :Disp "Hello, world!"

TuringModificar

   put "Hello, world!"

UNIX-style shellModificar

   echo 'Hello, world!'

Pseudocodice in InterlinguaModificar

   Algorithmo Hallo es:
       sia s:="Hello, world";
       imprime s;
   fin-Hallo

Ambiente graphic — como applicationes traditionalModificar

Visual BasicModificar

   MsgBox "Hello, world!"

C++ 'bindings' pro GTK toolkit de infographiaModificar

   #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;
   }

Qt toolkit (in C++)Modificar

   #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();
   }

Windows API (in C)Modificar

(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;
   }

JavaModificar

   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 webModificar

applet JavaModificar

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)Modificar

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!')

XULModificar

   <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <box align="center">
   <label value="Hello, world!" />
   </box>
   </window>

Formatos de documentosModificar

ASCIIModificar

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

HTMLModificar

   <html>
   <head>
   <title>Hallo, Mundo!</title>
   </head>
   <body>
   <p>Hello, world!</p>
   </body>
   </html>

PostScriptModificar

   /font /Courier findfont 24 scalefont
   font setfont
   100 100 moveto
   (Hello world!) show
   showpage

TeXModificar

   \font\HW=cmr10 scaled 3000
   \leftline{\HW Hello world}
   \bye

Ligamines externeModificar