作为所有编程语言的起始阶段,HELLO WORLD占据着无法改变的地位,所有中/英/法/德/美……版本的编程教材中,HELLO WORLD总是作为第一个TEST记录于书本之中,所有的编程第一步就在于此了!经典之中的经典!HELLO WORLD!
这个例程是从Kernighan & Ritchie 合著的《The C Programme Language》开始有的,因为它的简洁,实用,并包含了一个程序所应具有的一切,因此为后来的些类书的作者提供了范例,一直待续到今。
我们刚开始接触计算机语言大多从Hello world 开始,下面是各种语言的Hello world program:
[编辑本段]
AKA 控制台:
[编辑本段]
ABC语言的Hello World程序
WHILE (1=1) :
WRITE "Hello World "
[编辑本段]
Ada语言的Hello World程序
with Ada.Text_Io; use Ada.Text_Io;
procedure Hello is
begin
Put_Line ("Hello, world!");
end Hello;
[编辑本段]
AmigaE语言的Hello World程序
PROC main()
WriteF('Hello, World!')
ENDPROC
[编辑本段]
APL语言的Hello World程序
'Hello World'
[编辑本段]
Assembly语言的Hello World程序
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
[编辑本段]
DATASEG语言的Hello World程序
MSG DB 'Hello, world!$'
[编辑本段]
CODESEG语言的Hello World程序
MOV AX, @data
MOV DS, AX
MOV DX, OFFSET MSG
MOV AH, 09H ; DOS: output ASCII$ string
INT 21H
MOV AX, 4C00H
INT 21H
END
General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11
.MCALL .REGDEF,.TTYOUT,.EXIT
.REGDEF
HELLO: MOV #MSG,R1
MOVB (R1),R0
LOOP: .TTYOUT
MOVB +(R1),R0
BNE LOOP
.EXIT
MSG: .ASCIZ /HELLO, WORLD!/
.END HELLO
CISC: VAX, VMS, MACRO32
.title hello
term_name: .ascid /SYS$INPUT/
term_chan: .blkw 1
out_iosb: .blkq 1
msg: .asciz /Hello, world!/
.entry start,0
; establish a channel for terminal I/O
$assign_s devnam=term_name,-
chan=term_chan
blbc r0,error
; queue the I/O request
$qio_s chan=term_chan,-
func=#io$_writevblk,-
iosb=out_iosb,-
p1=msg,-
p2=#13
blbc r0,error
$exit_s ; normal exit
error: halt ; error condition
.end start
[编辑本段]
AWK语言的Hello World程序
BEGIN { print "Hello, world!" }
[编辑本段]
BASIC语言的Hello World程序:
PRINT "HELLO WORLD"
[编辑本段]
MS BASIC语言的Hello World程序
(traditional, unstructured)
10 PRINT "Hello, world!"
20 END
[编辑本段]
TI-BASIC语言的Hello World程序
isp "Hello, world!"
[编辑本段]
Structured BASIC语言的Hello World程序
print "Hello, world!"
[编辑本段]
BCPL语言的Hello World程序
GET "LIBHDR"
LET START () BE
$(
WRITES ("Hello, world!*N")
$)
[编辑本段]
C语言的Hello World程序
#include
int main(void)
{
printf("Hello, world!\n");
}
[编辑本段]
C++语言的Hello World程序
#include
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
[编辑本段]
C#语言的Hello World程序
class HelloWorldApp {
public static void Main() {
System.Console.WriteLine("Hello, world!");
}
}
[编辑本段]
Clean语言的Hello World程序
module hello
Start :: String
Start = "Hello, world"
[编辑本段]
CLIST语言的Hello World程序
PROC 0
WRITE Hello, World!
[编辑本段]
COBOL语言的Hello World程序
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
[编辑本段]
Common Lisp语言的Hello World程序
(format t "Hello world!~%")
[编辑本段]
Eiffel语言的Hello World程序
class HELLO_WORLD
creation
make
feature
make is
local
io:BASIC_IO
do
!!io
io.put_string("%N Hello, world!")
end -- make
end -- class HELLO_WORLD
[编辑本段]
Erlang语言的Hello World程序
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("Hello, world!\n").
[编辑本段]
Forth语言的Hello World程序
." Hello, world!" CR
[编辑本段]
Fortran语言的Hello World程序
PROGRAM HELLO
WRITE(*,10)
10 FORMAT('Hello, world!')
STOP
END
[编辑本段]
Haskell语言的Hello World程序
module HelloWorld (main) where
main = putStr "Hello World\n"
[编辑本段]
Iptscrae语言的Hello World程序
ON ENTER {
"Hello, " "World!" & SAY
}
[编辑本段]
Java语言的Hello World程序
public class Example{
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
[编辑本段]
Logo语言的Hello World程序
print [hello world!]
[编辑本段]
Lua语言的Hello World程序
print "Hello, world!"
[编辑本段]
MIXAL语言的Hello World程序
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程序
@echo off
echo Hello, world!
[编辑本段]
OCaml语言的Hello World程序
let _ =
print_endline "Hello world!";;
OPL
PROC hello:
PRINT "Hello, World"
ENDP
Pascal
program Hello;
begin
writeln('Hello, world!');
end.
[编辑本段]
Pascal语言的Hello World程序
program hello_world;
begin
writeln('Hello World!');
end.
[编辑本段]
Perl语言的Hello World程序
print "Hello, world!\n";
[编辑本段]
PHP语言的Hello World程序
print("Hello, world!");
?>
[编辑本段]
Pike语言的Hello World程序
#!/usr/local/bin/pike
int main() {
write("Hello, world!\n");
return 0;
}
[编辑本段]
PL/I语言的Hello World程序
Test: procedure options(main);
declare My_String char(20) varying initialize('Hello, world!');
put skip list(My_String);
end Test;
[编辑本段]
Python语言的Hello World程序
print "Hello, world!"
[编辑本段]
REXX语言的Hello World程序
also NetRexx and Object REXX
say "Hello, world!"
[编辑本段]
Ruby语言的Hello World程序
print "Hello, world!\n"
[编辑本段]
Sather语言的Hello World程序
class HELLO_WORLD is
main is
#OUT+"Hello World\n";
end;
end;
[编辑本段]
Scheme语言的Hello World程序
(display "Hello, world!")
(newline)
[编辑本段]
sed语言的Hello World程序
(requires at least one line of input)
sed -ne '1s/.*/Hello, world!/p'
[编辑本段]
Self语言的Hello World程序
'Hello, World!' uppercase print.
[编辑本段]
Smalltalk语言的Hello World程序
Transcript show: 'Hello, world!'
[编辑本段]
SML语言的Hello World程序
print "Hello, world!\n";
[编辑本段]
SNOBOL语言的Hello World程序
OUTPUT = "Hello, world!"
END
[编辑本段]
SQL语言的Hello World程序
create table MESSAGE (TEXT char(15));
insert into MESSAGE (TEXT) values ('Hello, world!');
select TEXT from MESSAGE;
drop table MESSAGE;
Or, more simply
print 'Hello, World.'
StarOffice Basic
sub main
print "Hello, World"
end sub
[编辑本段]
Tcl语言的Hello World程序
puts "Hello, world!"
[编辑本段]
Turing语言的Hello World程序
put "Hello, world!"
[编辑本段]
UNIX-style shell语言的Hello World程序
echo 'Hello, world!'
[编辑本段]
Romanian pseudocode语言的Hello World程序
(UBB Cluj-Napoca)Algoritmul Salut este:
fie s:="Hello, world";
tipareste s;
sf-Salut
[编辑本段]
传统图形界面应用开发工具:
C++ bindings for GTK graphics toolkit
#include
#include
#include
#include
using namespace std;
class HelloWorld : public Gtk::Window {
public:
HelloWorld();
virtual ~HelloWorld();
protected:
Gtk::Button m_button;
virtual void on_button_clicked();
};
HelloWorld::HelloWorld()
: m_button("Hello, world!") {
set_border_width(10);
m_button.signal_clicked().connect(SigC:lot(*this,
&HelloWorld::on_button_clicked));
add(m_button);
m_button.show();
}
HelloWorld::~HelloWorld() {}
void HelloWorld::on_button_clicked() {
cout << "Hello, world!" << endl;
}
int main (int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
HelloWorld helloworld;
Gtk::Main::run(helloworld);
return 0;
}
[编辑本段]
Java语言的Hello World程序
import java.awt.*;
import java.awt.event.*;
public class HelloFrame extends Frame {
HelloFrame(String title) {
super(title);
}
public void paint(Graphics g) {
super.paint;
java.awt.Insets ins = this.getInsets();
g.drawString("Hello, world!", ins.left + 25, ins.top + 25);
}
public static void main(String args [])
{
HelloFrame fr = new HelloFrame("Hello");
fr.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit( 0 );
}
}
);
fr.setResizable(true);
fr.setSize(500, 100);
fr.setVisible(true);
}
}
Qt toolkit (in C++)
#include
#include
#include
#include
class HelloWorld : public QWidget
{
Q_OBJECT
[编辑本段]
public语言的Hello World程序
HelloWorld();
virtual ~HelloWorld();
public slots:
void handleButtonClicked();
QPushButton *mPushButton;
};
HelloWorld::HelloWorld() :
QWidget(),
mPushButton(new QPushButton("Hello, World!", this))
{
connect(mPushButton, SIGNAL(clicked()), this, SLOT(handleButtonClicked()));
}
HelloWorld::~HelloWorld() {}
void HelloWorld::handleButtonClicked()
{
std::cout << "Hello, World!" << std::endl;
}
int main(int argc, char *argv[])
{
[编辑本段]
QApplication app语言的Hello World程序
(argc, argv);
HelloWorld helloWorld;
app.setMainWidget(&helloWorld);
helloWorld.show();
return app.exec();
}
[编辑本段]
Visual Basic语言的Hello World程序
1.信息框
MsgBox "Hello, world!"
2.输出到窗体
Print "Hello, world!"
[编辑本段]
Windows API (in C)语言的Hello World程序
#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))
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;
}
[编辑本段]
基于web图形用户界面:
[编辑本段]
Java applet语言的Hello World程序
Java applets work in conjunction with HTML files.
HelloWorld Program says:
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello, world!", 100, 50);
}
}
JavaScript, aka ECMAScript语言的Hello World程序
JavaScript is a scripting language used in HTML files. To demo this program Cut and Paste the following code into any HTML file.
οnclick="javascript:helloWorld();">Hello World Example
An easier method uses JavaScript implicitly, calling the reserved alert function. Cut and paste the following line inside the .... HTML tags.
Hello World Example
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程序
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
[编辑本段]
HTML语言的Hello World程序
Hello, world!
[编辑本段]
PostScript语言的Hello World程序
/font /Courier findfont 24 scalefont
font setfont
100 100 moveto
(Hello world!) show
showpage
[编辑本段]
TeX语言的Hello World程序
\font\HW=cmr10 scaled 3000
\leftline{\HW Hello world}
\bye
[编辑本段]
LaTeX语言的Hello World程序
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
[编辑本段]
批处理语言的Hello World程序
echo Hello World!
[编辑本段]
易语言的Hello World程序
.子程序 __启动窗口_创建完毕
信息框 (“Hello, world!”, 0, )
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试