作为所有编程语言的起始阶段,HELLO WORLD 占据着无法改变的地位,所有中 / 英 / 法 / 德 / 美…… 版本的编程教材中,HELLO WORLD 总是作为第一个 TEST 记录于书本之中,所有的编程第一步就在于此了!经典之中的经典!HELLO WORLD! 这个例程是从 Kernighan & Ritchie 合著的《The C Programme Language》开始有的,因为它的简洁,实用,并包含了一个程序所应具有的一切,因此为后来的些类书的作者提供了范例,一直待续到今。 我们刚开始接触计算机语言大多从 Hello world 开始,下面是各种语言的 Hello world program:
AKA 控制台:
ABC 语言的 Hello World 程序
1 2
WHILE (1=1) : WRITE "Hello World "
Ada 语言的 Hello World 程序
1 2 3 4 5
with Ada.Text_Io; use Ada.Text_Io; procedureHellois begin Put_Line ("Hello, world!"); end Hello;
AmigaE 语言的 Hello World 程序
1 2 3
PROC main() WriteF('Hello, World!') ENDPROC
APL 语言的 Hello World 程序
1
'Hello World'
Assembly 语言的 Hello World 程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Accumulator-only architecture: DEC PDP-8, PAL-III assembler See the Example section of the PDP-8 article. Accumulator + index register machine: MOS 6502, CBM, ca65 asm MSG: .ASCIIZ "Hello, world!" LDX #0 LDA MSG,X ; load initial char @LP: JSR $FFD2 ; CHROUT CBM KERNAL INX LDA MSG,X BNE @LP RTS Accumulator/Index microcoded machine: Data General Nova, RDOS See the example section of the Nova article. Expanded accumulator machine: Intel x86, MS-DOS, TASM MODEL SMALL IDEAL STACK 100H
TERM EQU 19 the MIX console device number ORIG 1000 start address START OUT MSG(TERM) output data at address MSG HLT halt execution MSG ALF "MIXAL" ALF " HELL" ALF "O WOR" ALF "LD " END START end of the program
MSDOS batch 语言的 Hello World 程序
1 2
@echo off echo Hello, world!
OCaml 语言的 Hello World 程序
1 2 3 4 5 6 7 8 9 10 11
let _ = print_endline "Hello world!";; OPL PROC hello: PRINT "Hello, World" ENDP Pascal program Hello; begin writeln('Hello, world!'); end.
Pascal 语言的 Hello World 程序
1 2 3 4
program hello_world; begin writeln('Hello World!'); end.
Perl 语言的 Hello World 程序
1
print"Hello, world!\n";
PHP 语言的 Hello World 程序
1 2 3
<?php print("Hello, world!"); ?>
Pike 语言的 Hello World 程序
1 2 3 4 5
#!/usr/local/bin/pike int main() { write("Hello, world!\n"); return 0; }
PL/I 语言的 Hello World 程序
1 2 3 4
Test: procedure options(main); declare My_String char(20) varying initialize('Hello, world!'); put skip list(My_String); end Test;
Python 语言的 Hello World 程序
1
print"Hello, world!"
REXX 语言的 Hello World 程序
1 2
also NetRexx and Object REXX say "Hello, world!"
Ruby 语言的 Hello World 程序
1
print "Hello, world!\n"
Sather 语言的 Hello World 程序
1 2 3 4 5
class HELLO_WORLD is main is #OUT+"Hello World\n"; end; end;
Scheme 语言的 Hello World 程序
1 2
(display"Hello, world!") (newline)
sed 语言的 Hello World 程序
1 2
(requires at least one line of input) sed -ne '1s/.*/Hello, world!/p'
Self 语言的 Hello World 程序
1
'Hello, World!' uppercase print.
Smalltalk 语言的 Hello World 程序
1
Transcript show: 'Hello, world!'
SML 语言的 Hello World 程序
1
print "Hello, world!\n";
SNOBOL 语言的 Hello World 程序
1 2
OUTPUT = "Hello, world!" END
SQL 语言的 Hello World 程序
1 2 3 4 5 6 7 8 9 10
createtable MESSAGE (TEXT char(15)); insertinto MESSAGE (TEXT) values ('Hello, world!'); select TEXT from MESSAGE; droptable MESSAGE; Or, more simply print 'Hello, World.' StarOffice Basic sub main print "Hello, World" end sub
Tcl 语言的 Hello World 程序
1
puts"Hello, world!"
Turing 语言的 Hello World 程序
1
put "Hello, world!"
UNIX-style shell 语言的 Hello World 程序
1
echo 'Hello, world!'
Romanian pseudocode 语言的 Hello World 程序
1 2 3 4
(UBB Cluj-Napoca)Algoritmul Salut este: fie s:="Hello, world"; tipareste s; sf-Salut
#include 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)) return0; 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); } return0; }
基于 web 图形用户界面:
Java applet 语言的 Hello World 程序
1 2 3 4 5 6 7 8 9
Java applets work in conjunction with HTML files. HelloWorld Program says: import java.applet.*; import java.awt.*; publicclassHelloWorldextendsApplet { publicvoidpaint(Graphics g) { g.drawString("Hello, world!", 100, 50); } }
JavaScript, aka ECMAScript 语言的 Hello World 程序
1 2 3 4 5 6
JavaScript is a scripting language used inHTML files. To demo this program Cut and Paste the following code into any HTML file. onclick="javascript:helloWorld();">HelloWorldExample An easier method uses JavaScript implicitly, calling the reserved alert function. Cut and paste the following line inside the .... HTML tags. HelloWorldExample An even easier method involves using popular browsers' support for the virtual 'javascript' protocol to execute JavaScript code. Enter the following as an Internet address (usually by pasting into the address box): javascript:alert('Hello, world!')
文档格式:
ASCII 语言的 Hello World 程序
1 2
The following sequence of characters, expressed in hexadecimal notation (with carriage return and newline characters at end of sequence): 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A