您的位置:首页 > 其它

茶余饭后来回顾我们熟悉的“Hello world program”

2004-07-18 16:00 465 查看
我们刚开始接触计算机语言大多从Helloworld开始,下面演示各种语言的Helloworldprogram:
AKA控制台
ABC
WHILE(1=1):
WRITE"HelloWorld"
Ada
withAda.Text_Io;useAda.Text_Io;
procedureHellois
begin
Put_Line("Hello,world!");
endHello;
AmigaE
PROCmain()
WriteF('Hello,World!')
ENDPROC
APL
'HelloWorld'
Assemblylanguage
Accumulator-onlyarchitecture:DECPDP-8,PAL-IIIassembler
SeetheExamplesectionofthePDP-8article.

Accumulator+indexregistermachine:MOS6502,CBM,ca65asm
MSG:.ASCIIZ"Hello,world!"
LDX#0
LDAMSG,X;loadinitialchar
@LP:JSR$FFD2;CHROUTCBMKERNAL
INX
LDAMSG,X
BNE@LP
RTS
Accumulator/Indexmicrocodedmachine:DataGeneralNova,RDOS
SeetheexamplesectionoftheNovaarticle.
Expandedaccumulatormachine:Intelx86,MS-DOS,TASM
MODELSMALL
IDEAL
STACK100H
DATASEG
MSGDB'Hello,world!$'
CODESEG
MOVAX,@data
MOVDS,AX
MOVDX,OFFSETMSG
MOVAH,09H;DOS:outputASCII$string
INT21H
MOVAX,4C00H
INT21H
END
General-purpose-registerCISC:DECPDP-11,RT-11,MACRO-11
.MCALL.REGDEF,.TTYOUT,.EXIT
.REGDEF
HELLO:MOV#MSG,R1
MOVB(R1),R0
LOOP:.TTYOUT
MOVB+(R1),R0
BNELOOP
.EXIT
MSG:.ASCIZ/HELLO,WORLD!/
.ENDHELLO
CISC:VAX,VMS,MACRO32
.titlehello
term_name:.ascid/SYS$INPUT/
term_chan:.blkw1
out_iosb:.blkq1
msg:.asciz/Hello,world!/

.entrystart,0

;establishachannelforterminalI/O
$assign_sdevnam=term_name,-
chan=term_chan
blbcr0,error

;queuetheI/Orequest
$qio_schan=term_chan,-
func=#io$_writevblk,-
iosb=out_iosb,-
p1=msg,-
p2=#13
blbcr0,error

$exit_s;normalexit

error:halt;errorcondition
.endstart
AWK
BEGIN{print"Hello,world!"}
BASICMSBASIC(traditional,unstructured)
10PRINT"Hello,world!"
20ENDTI-BASIC


isp"Hello,world!"StructuredBASIC
print"Hello,world!"BCPL
GET"LIBHDR"
LETSTART()BE
$(
WRITES("Hello,world!*N")
$)

C
#include
intmain(void){
printf("Hello,world!/n");
return0;
}
C++
#include
usingnamespacestd;
intmain(){
cout<<"Hello,world!"<<endl;
return0;
}
C#
classHelloWorldApp{
publicstaticvoidMain(){
System.Console.WriteLine("Hello,world!");
}
}
Clean
modulehello
Start::String
Start="Hello,world"
CLIST
PROC0
WRITEHello,World!
COBOL
IDENTIFICATIONDIVISION.
PROGRAM-ID.HELLO-WORLD.
ENVIRONMENTDIVISION.
DATADIVISION.
PROCEDUREDIVISION.
DISPLAY"Hello,world!".
STOPRUN.
CommonLisp
(formatt"Helloworld!~%")
Eiffel
classHELLO_WORLD
creation
make
feature
makeis
local
io:BASIC_IO
do
!!io
io.put_string("%NHello,world!")
end--make
end--classHELLO_WORLD
Erlang
-module(hello).
-export([hello_world/0]).
hello_world()->io:fwrite("Hello,world!/n").
Forth
."Hello,world!"CR
Fortran(偶大学学的课程)
PROGRAMHELLO
WRITE(*,10)
10FORMAT('Hello,world!')
STOP
END
Haskell
moduleHelloWorld(main)where
main=putStr"HelloWorld/n"

Iptscrae
ONENTER{
"Hello,""World!"&SAY
}
Java
publicclassHello{
publicstaticvoidmain(String[]args){
System.out.println("Hello,world!");
}
}
Logo
print[helloworld!]
Lua
print"Hello,world!"
MIXAL
TERMEQU19theMIXconsoledevicenumber
ORIG1000startaddress
STARTOUTMSG(TERM)outputdataataddressMSG
HLThaltexecution
MSGALF"MIXAL"
ALF"HELL"
ALF"OWOR"
ALF"LD"
ENDSTARTendoftheprogram
MSDOSbatch
@echooff
echoHello,world!
OCaml
let_=
print_endline"Helloworld!";;OPL
PROChello:
PRINT"Hello,World"
ENDPPascal
programHello;
begin
writeln('Hello,world!');
end.Perl
print"Hello,world!/n";
PHP
print("Hello,world!");
?>
Pike
#!/usr/local/bin/pike
intmain(){
write("Hello,world!/n");
return0;
}PL/I
Test:procedureoptions(main);
declareMy_Stringchar(20)varyinginitialize('Hello,world!');
putskiplist(My_String);
endTest;
Python
print"Hello,world!"
REXX,alsoNetRexxandObjectREXX
say"Hello,world!"
Ruby
print"Hello,world!/n"
Sather
classHELLO_WORLDis
mainis
#OUT+"HelloWorld/n";
end;
end;
Scheme
(display"Hello,world!")
(newline)
sed(requiresatleastonelineofinput)
sed-ne'1s/.*/Hello,world!/p'
Self
'Hello,World!'uppercaseprint.

Smalltalk
Transcriptshow:'Hello,world!'
SML
print"Hello,world!/n";
SNOBOL
OUTPUT="Hello,world!"
END
SQL
createtableMESSAGE(TEXTchar(15));
insertintoMESSAGE(TEXT)values('Hello,world!');
selectTEXTfromMESSAGE;
droptableMESSAGE;
Or,moresimply

print'Hello,World.'
StarOfficeBasic
submain
print"Hello,World"
endsub
Tcl
puts"Hello,world!"

Turing
put"Hello,world!"
UNIX-styleshell
echo'Hello,world!'
Romanianpseudocode(UBBCluj-Napoca)
AlgoritmulSaluteste:
fies:="Hello,world";
tiparestes;
sf-Salut
传统图形界面应用开发工具
C++bindingsforGTKgraphicstoolkit
#include
#include
#include
#include
usingnamespacestd;
classHelloWorld:publicGtk::Window{
public:
HelloWorld();
virtual~HelloWorld();
protected:
Gtk::Buttonm_button;
virtualvoidon_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(){}
voidHelloWorld::on_button_clicked(){
cout<<"Hello,world!"<<endl;
}
intmain(intargc,char*argv[]){
Gtk::Mainkit(argc,argv);
HelloWorldhelloworld;
Gtk::Main::run(helloworld);
return0;
}
Java
importjava.awt.*;
importjava.awt.event.*;
publicclassHelloFrameextendsFrame{
HelloFrame(Stringtitle){
super(title);
}
publicvoidpaint(Graphicsg){
super.paint

;
java.awt.Insetsins=this.getInsets();
g.drawString("Hello,world!",ins.left+25,ins.top+25);
}
publicstaticvoidmain(Stringargs[])
{
HelloFramefr=newHelloFrame("Hello");
fr.addWindowListener(
newWindowAdapter(){
publicvoidwindowClosing(WindowEvente)
{
System.exit(0);
}
}
);
fr.setResizable(true);
fr.setSize(500,100);
fr.setVisible(true);
}
}

Qttoolkit(inC++)
#include
#include
#include
#include
classHelloWorld:publicQWidget
{
Q_OBJECT
public:
HelloWorld();
virtual~HelloWorld();
publicslots:
voidhandleButtonClicked();
QPushButton*mPushButton;
};
HelloWorld::HelloWorld():
QWidget(),
mPushButton(newQPushButton("Hello,World!",this))
{
connect(mPushButton,SIGNAL(clicked()),this,SLOT(handleButtonClicked()));
}
HelloWorld::~HelloWorld(){}
voidHelloWorld::handleButtonClicked()
{
std::cout<<"Hello,World!"<<std::endl;
}
intmain(intargc,char*argv[])
{
QApplicationapp(argc,argv);
HelloWorldhelloWorld;
app.setMainWidget(&helloWorld);
helloWorld.show();
returnapp.exec();
}
VisualBasic
MsgBox"Hello,world!"
WindowsAPI(inC)
#include
LRESULTCALLBACKWindowProcedure(HWND,UINT,WPARAM,LPARAM);
charszClassName[]="MainWnd";
HINSTANCEhInstance;
intWINAPIWinMain(HINSTANCEhInst,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow)
{
HWNDhwnd;
MSGmsg;
WNDCLASSEXwincl;
hInstance=hInst;

wincl.cbSize=sizeof(WNDCLASSEX);
wincl.cbClsExtra=0;
wincl.cbWndExtra=0;
wincl.style=0;
wincl.hInstance=hInstance;
wincl.lpszClassName=szClassName;
wincl.lpszMenuName=NULL;//Nomenu
wincl.lpfnWndProc=WindowProcedure;
wincl.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);//Colorofthewindow
wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);//EXEicon
wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);//Smallprogramicon
wincl.hCursor=LoadCursor(NULL,IDC_ARROW);//Cursor

if(!RegisterClassEx(&wincl))
return0;
hwnd=CreateWindowEx(0,//Noextendedwindowstyles
szClassName,//Classname
"",//Windowcaption
WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX,
CW_USEDEFAULT,CW_USEDEFAULT,//LetWindowsdecidetheleftandtoppositionsofthewindow
120,50,//Widthandheightofthewindow,
NULL,NULL,hInstance,NULL);
//Makethewindowvisibleonthescreen
ShowWindow(hwnd,nCmdShow);

//Runthemessageloop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
returnmsg.wParam;
}
LRESULTCALLBACKWindowProcedure(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
PAINTSTRUCTps;
HDChdc;
switch(message)
{
caseWM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,15,3,"Hello,world!",13);
EndPaint(hwnd,&ps);
break;
caseWM_DESTROY:
PostQuitMessage(0);
break;
default:
returnDefWindowProc(hwnd,message,wParam,lParam);
}
return0;
}

基于web图形用户界面

Javaapplet
JavaappletsworkinconjunctionwithHTMLfiles.

HelloWorldProgramsays:

???

importjava.applet.*;
importjava.awt.*;
publicclassHelloWorldextendsApplet{
publicvoidpaint(Graphicsg){
g.drawString("Hello,world!",100,50);
}
}
JavaScript,akaECMAScript
JavaScriptisascriptinglanguageusedinHTMLfiles.TodemothisprogramCutandPastethefollowingcodeintoanyHTMLfile.

????functionhelloWorld()
????{
????????javascript:alert("Hello,world!");
????}
????
onclick="javascript:helloWorld();">HelloWorldExample
AneasiermethodusesJavaScriptimplicitly,callingthereservedalertfunction.Cutandpastethefollowinglineinsidethe....HTMLtags.
HelloWorldExample
Aneveneasiermethodinvolvesusingpopularbrowsers'supportforthevirtual'javascript'protocoltoexecuteJavaScriptcode.EnterthefollowingasanInternetaddress(usuallybypastingintotheaddressbox):
javascript:alert('Hello,world!')
XULhttp://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
文档格式ASCII
Thefollowingsequenceofcharacters,expressedinhexadecimalnotation(withcarriagereturnandnewlinecharactersatendofsequence):
48656C6C6F2C20776F726C64210D0A
HTML

Hello,world!

PostScript

/font/Courierfindfont24scalefont
fontsetfont
100100moveto
(Helloworld!)show
showpage
TeX
/font/HW=cmr10scaled3000
/leftline{/HWHelloworld}
/bye

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: