Hello World
De Wikipedia, le encyclopedia libere
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:
[modificar] Ambiente textual
[modificar] Ada
with Ada.Text_Io; use Ada.Text_Io; procedure Hello is begin Put_Line ("Hello, world!"); end Hello;
[modificar] linguage de montage (assembly) (UCP x86, MS-DOS, syntaxe TASM)
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
[modificar] AWK
BEGIN { print "Hello, world!" }
[modificar] BASIC
Traditional - BASIC non structurate 10 PRINT "Hello, world!" 20 END
Versiones plus moderne - BASIC structurate print "Hello, world!"
[modificar] BCPL
GET "LIBHDR" LET START () BE $( WRITES ("Hello, world!*N") $)
[modificar] C
#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
[modificar] C++
#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; }
[modificar] C#
class AppHalloMundo { public static void Main() { System.Console.WriteLine("Hello, world!"); } }
[modificar] Clean
module hallo
Start :: String Start = "Hello, world"
[modificar] COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. HALLO-MUNDO.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION. DISPLAY "Hello, world!". STOP RUN.
[modificar] Common Lisp
(format t "Hello world!~%")
[modificar] Eiffel
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
[modificar] Erlang
-module(hallo). -export([hallo_mundo/0]).
hallo_mundo() -> io:fwrite("Hello, world!\n").
[modificar] Forth
." Hello, world!" CR
[modificar] Fortran
PROGRAM HALLO WRITE(*,10) 10 FORMAT('Hello, world!') STOP END
[modificar] Haskell
module HalloMundo (main) where
main = putStr "Hello World\n"
[modificar] Iptscrae
ON ENTER { "Hello, " "World!" & SAY }
[modificar] Java
public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } }
[modificar] Lua
print "Hello, world!"
[modificar] MIXAL
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
[modificar] Linguage de lot de MS-DOS
@echo off echo Hello, world!
[modificar] OCaml
let _ = print_endline "Hello world!";;
[modificar] OPL
PROC hallo: PRINT "Hello, World" ENDP
[modificar] Pascal
program Hallo(output); begin writeln('Hello, world!') end.
[modificar] Perl
print "Hello, world!\n";
[modificar] PHP
<?php print("Hello, world!"); ?>
[modificar] Pike
#!/usr/local/bin/pike int main() { write("Hello, world!\n"); return 0; }
[modificar] PL/I
Prova: procedure options(main); declare Mi_Vector char(20) varying initialize('Hello, world!'); put skip list(Mi_Vector); end Prova;
[modificar] Python
print "Hello, world!"
[modificar] REXX
say "Hello, world!"
[modificar] Ruby
print "Hello, world!\n"
[modificar] Scheme
(display "Hello, world!") (newline)
[modificar] sed (require al minus un linea de input (de stdin))
sed -ne '1s/.*/Hello, world!/p'
[modificar] Seed7
$ include "seed7_05.s7i"; const proc: main is func begin writeln("Hello, world!"); end func;
[modificar] Smalltalk
Transcript show: 'Hello, world!'
[modificar] SML
print "Hello, world!\n";
[modificar] SNOBOL
OUTPUT = "Hello, world!" END
[modificar] SQL
create table HALLO (TEXTO char(15)); insert into HALLO (TEXTO) values ('Hello, world!'); select TEXTO from HALLO; drop table HALLO;
[modificar] StarOffice Basic
sub main print "Hello, World" end sub
[modificar] Tcl
puts "Hello, world!"
[modificar] TI-BASIC
:Disp "Hello, world!"
[modificar] Turing
put "Hello, world!"
[modificar] UNIX-style shell
echo 'Hello, world!'
[modificar] Pseudocodice in Interlingua
Algorithmo Hallo es: sia s:="Hello, world"; imprime s; fin-Hallo
[modificar] Ambiente graphic — como applicationes traditional
[modificar] Visual Basic
MsgBox "Hello, world!"
[modificar] C++ 'bindings' pro GTK toolkit de infographia
#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; }
[modificar] Qt toolkit (in C++)
#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(); }
[modificar] Windows API (in C)
(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; }
[modificar] Java
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); } }
[modificar] Ambiente graphic basate super navigator del web
[modificar] applet Java
- 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); } }
[modificar] JavaScript (o ECMAScript)
- 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!')
[modificar] XUL
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <box align="center"> <label value="Hello, world!" /> </box> </window>
[modificar] Formatos de documentos
[modificar] ASCII
- 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
[modificar] HTML
<html> <head> <title>Hallo, Mundo!</title> </head> <body>
Hello, world!
</body> </html>
[modificar] PostScript
/font /Courier findfont 24 scalefont font setfont 100 100 moveto (Hello world!) show showpage
[modificar] TeX
\font\HW=cmr10 scaled 3000 \leftline{\HW Hello world} \bye
[modificar] Ligamines externe
- http://www.latech.edu/~acm/HelloWorld.shtml — ACM Projecto "Hello World" (in anglese)
- http://www.cuillin.demon.co.uk/nazz/trivia/hw/hello_world.html — Un collection de programmas "Hello World" (in anglese)
- http://99-bottles-of-beer.ls-la.net/ — Un programma plus complexe in multissime linguages (in anglese)