Hello World

De Wikipedia, le encyclopedia libere
Saltar a: navigation, cercar

Un programma "Hello, world!" ("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).

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 (ma un que clarmente indica su successo).

Ben que parve programmas de prova ha existite desde 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 | modificar fonte]

Ada[modificar | modificar fonte]

   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 | modificar fonte]

   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

AWK[modificar | modificar fonte]

   BEGIN { print "Hello, world!" }

BASIC[modificar | modificar fonte]

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

BCPL[modificar | modificar fonte]

   GET "LIBHDR"

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

C[modificar | modificar fonte]

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

C++[modificar | modificar fonte]

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

C#[modificar | modificar fonte]

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

Clean[modificar | modificar fonte]

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

COBOL[modificar | modificar fonte]

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

Common Lisp[modificar | modificar fonte]

   (format t "Hello world!~%")

Eiffel[modificar | modificar fonte]

   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

Erlang[modificar | modificar fonte]

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

Forth[modificar | modificar fonte]

   ." Hello, world!" CR

Fortran[modificar | modificar fonte]

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

Haskell[modificar | modificar fonte]

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

Iptscrae[modificar | modificar fonte]

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

Java[modificar | modificar fonte]

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

Lua[modificar | modificar fonte]

   print "Hello, world!"

MIXAL[modificar | modificar fonte]

    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 | modificar fonte]

   @echo off
   echo Hello, world!

OCaml[modificar | modificar fonte]

   let _ =
      print_endline "Hello world!";;

OPL[modificar | modificar fonte]

   PROC hallo:
     PRINT "Hello, World"
   ENDP

Pascal[modificar | modificar fonte]

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

Perl[modificar | modificar fonte]

   print "Hello, world!\n";

PHP[modificar | modificar fonte]

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

Pike[modificar | modificar fonte]

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

PL/I[modificar | modificar fonte]

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

Python[modificar | modificar fonte]

   print "Hello, world!"

REXX[modificar | modificar fonte]

   say "Hello, world!"

Ruby[modificar | modificar fonte]

   print "Hello, world!\n"

Scheme[modificar | modificar fonte]

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

sed (require al minus un linea de input (de stdin))[modificar | modificar fonte]

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

Seed7[modificar | modificar fonte]

   $ include "seed7_05.s7i";

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

Smalltalk[modificar | modificar fonte]

   Transcript show: 'Hello, world!'

SML[modificar | modificar fonte]

   print "Hello, world!\n";

SNOBOL[modificar | modificar fonte]

       OUTPUT = "Hello, world!"
   END

SQL[modificar | modificar fonte]

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

StarOffice Basic[modificar | modificar fonte]

   sub main
   print "Hello, World"
   end sub

Tcl[modificar | modificar fonte]

   puts "Hello, world!"

TI-BASIC[modificar | modificar fonte]

   :Disp "Hello, world!"

Turing[modificar | modificar fonte]

   put "Hello, world!"

UNIX-style shell[modificar | modificar fonte]

   echo 'Hello, world!'

Pseudocodice in Interlingua[modificar | modificar fonte]

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

Ambiente graphic — como applicationes traditional[modificar | modificar fonte]

Visual Basic[modificar | modificar fonte]

   MsgBox "Hello, world!"

C++ 'bindings' pro GTK toolkit de infographia[modificar | modificar fonte]

   #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 | modificar fonte]

   #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 | modificar fonte]

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

Java[modificar | modificar fonte]

   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 | modificar fonte]

applet Java[modificar | modificar fonte]

Applets Java son 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 | modificar fonte]

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

XUL[modificar | modificar fonte]

   <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 | modificar fonte]

ASCII[modificar | modificar fonte]

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[modificar | modificar fonte]

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

PostScript[modificar | modificar fonte]

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

TeX[modificar | modificar fonte]

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

Ligamines externe[modificar | modificar fonte]