Hello World程序样例

以下是用不同编程语言写成的Hello World程序的列表：
打印到终端.
ActionScript.
<syntaxhighlight lang="actionscript">
trace("Hello, world!");
</syntaxhighlight>
Ada.
<syntaxhighlight lang="ada">
with TEXT_IO;
procedure HELLO is
begin
end HELLO;
</syntaxhighlight>
-{zh-hans:汇编; zh-hant:组合;}-语言.
x86 CPU，GNU/Linux，NASM.
<syntaxhighlight lang="asm">
</syntaxhighlight>
x86 CPU、Windows、MASM32.
<syntaxhighlight lang="ASM"> .386
szCaption db "A MessageBox!", 0
szText db "Hello, world!", 0
start:
</syntaxhighlight>
8086作业系统（NASM）.
<syntaxhighlight lang="asm">
16
org 0x7c00
DispStr:
BootMessage: db "Hello, world!"
times 510-($-$$) db 0x0
dw 0xaa55; Bootable Mark
</syntaxhighlight>
AutoIt.
<syntaxhighlight lang="autoit">MsgBox(1,",'Hello, world!')</syntaxhighlight>
AWK.
<syntaxhighlight lang="text">
</syntaxhighlight>
Bash (或其他Unix Shell).
<syntaxhighlight lang="bash"> echo 'Hello, world!'</syntaxhighlight>
或者：
<syntaxhighlight lang="bash"> printf 'Hello, world!\n'</syntaxhighlight>
BASIC.
传统版 BASIC（例如 GWBASIC）：
<syntaxhighlight lang="qbasic">
10 PRINT "Hello, world!"
20 END
</syntaxhighlight>
或：
<syntaxhighlight lang="qbasic">
10 PRINT "Hello, world!"
</syntaxhighlight>
或在提示符输入：
<syntaxhighlight lang="qbasic">
? "Hello, world!"
</syntaxhighlight>
现代版 BASIC（例如 Quick BASIC）：
<syntaxhighlight lang="qbasic">
Print "Hello, world!"
</syntaxhighlight>
以下的语句，在 Quick BASIC 中同样有效：
<syntaxhighlight lang="qbasic">
? "Hello, world!"
</syntaxhighlight>
BCPL.
<syntaxhighlight lang="text">
GET "LIBHDR"
LET START () BE
</syntaxhighlight>
Brainfuck.
<syntaxhighlight lang="bf">
++++++++[>+++++++>++++++++++>+++>+Â«Â«.
>++.>+.+++++++..+++.>++.Â«+++++++++++++++.
</syntaxhighlight>
Blitz Basic.
<syntaxhighlight lang=BlitzBasic >
Print "Hello, world!"
WaitKey
</syntaxhighlight>
BOO.
<syntaxhighlight lang="python">
print "Hello, world!"
</syntaxhighlight>
C.
<syntaxhighlight lang="c">
int main(void)
</syntaxhighlight>
或者：
<syntaxhighlight lang="c">
int main(void)
</syntaxhighlight>
CoffeeScript.
<syntaxhighlight lang="coffeescript">
console.log 'Hello, world!'
</syntaxhighlight>
或者：
<syntaxhighlight lang="coffeescript">
alert 'Hello, world!'
</syntaxhighlight>
C++.
<syntaxhighlight lang="cpp">
int main()
</syntaxhighlight>
或者：
<syntaxhighlight lang="cpp">
using namespace std;
int main()
</syntaxhighlight>
C++/CLI.
<syntaxhighlight lang="cpp">
int main()
</syntaxhighlight>
C# (C Sharp).
<syntaxhighlight lang="csharp">
using System
class HelloWorldApp
</syntaxhighlight>
或者（仅用于Microsoft Windows）
<syntaxhighlight lang="csharp">
class HelloWorldApp
</syntaxhighlight>
或者（使用附加的Windows Forms）
<syntaxhighlight lang="csharp">
using System.Windows.Forms;
class HelloWorldApp
</syntaxhighlight>
COBOL.
<syntaxhighlight lang=cobol>
</syntaxhighlight>
Common Lisp.
<syntaxhighlight lang="lisp">
"Hello world!"
</syntaxhighlight>
DOS批处理.
<syntaxhighlight lang="dos">
@echo Hello, world!
</syntaxhighlight>
对于MS-DOS 3.0或更低版本：
<syntaxhighlight lang="dos">
echo off
cls
echo Hello, world!
</syntaxhighlight>
Eiffel.
<syntaxhighlight lang="eiffel">
class HELLO_WORLD
creation
feature
end -- class HELLO_WORLD
</syntaxhighlight>
Erlang.
<syntaxhighlight lang="text">
</syntaxhighlight>
Forth.
<syntaxhighlight lang="text">
." Hello, world!" CR
</syntaxhighlight>
Fortran.
<syntaxhighlight lang="fortran">
</syntaxhighlight>
Go.
<syntaxhighlight lang="go">
package main
import "fmt"
func main() {
</syntaxhighlight>
INTERCAL.
<syntaxhighlight lang=intercal>
PLEASE DO ,1 <- #13
DO ,1 SUB #1 <- #238
DO ,1 SUB #2 <- #112
DO ,1 SUB #3 <- #112
DO ,1 SUB #4 <- #0
DO ,1 SUB #5 <- #64
DO ,1 SUB #6 <- #238
DO ,1 SUB #7 <- #26
DO ,1 SUB #8 <- #248
DO ,1 SUB #9 <- #168
DO ,1 SUB #10 <- #24
DO ,1 SUB #11 <- #16
DO ,1 SUB #12 <- #158
DO ,1 SUB #13 <- #52
PLEASE READ OUT ,1
PLEASE GIVE UP
</syntaxhighlight>
Java.
<syntaxhighlight lang="java">
public class Hello
</syntaxhighlight>
或者：
<syntaxhighlight lang="java">
class HelloWorld
</syntaxhighlight>
JavaScript.
该代码适用于浏览器控制台以及Node.js等服务器端运行环境。
<syntaxhighlight lang="javascript">
console.log("Hello, World!");
</syntaxhighlight>
Julia.
<syntaxhighlight lang="julia">
println("Hello, world!") 
</syntaxhighlight>
Lisp.
<syntaxhighlight lang="lisp">
"hello, world"
</syntaxhighlight>
Lua.
<syntaxhighlight lang="lua">
print "Hello, world!"
</syntaxhighlight>
Matlab.
<syntaxhighlight lang="matlab">
disp('hello world!')
</syntaxhighlight>
Metapost.
<syntaxhighlight lang="text">
beginfig(1);
draw (0,0)--(0,10);
draw (0,5)--(5,5);
draw (5,0)--(5,10);
draw (12,0)--(7,0)--(7,10)--(12,10);
draw (12,5)--(7,5);
draw (14,10)--(14,0)--(19,0);
draw (21,10)--(21,0)--(26,0);
draw (28,5)...(30.5,0)...(33,5)...(30.5,10)...cycle;
draw (38,10)--(39.25,0)--(40.5,10)--(41.75,0)--(43,10);
draw (45,5)...(47.5,0)...(50,5)...(47.5,10)...cycle;
draw (52,0)--(52,10);
draw (52,10)..(57,4)..(52,6.5);
draw (52,5)--(57,0);
draw (61,10)--(61,0)--(66,0);
draw (68,10)--(68,0)..(73,5)..cycle;
endfig;
end
</syntaxhighlight>
MIXAL.
<syntaxhighlight lang="text">
TERM EQU 19 the MIX console device number
START OUT MSG(TERM) output data at address MSG
MSG ALF "MIXAL"
</syntaxhighlight>
Nuva.
<syntaxhighlight lang="text">
<..直接输出..>
Hello, world!
<..或者..>
</syntaxhighlight>
Objective-C.
<syntaxhighlight lang="objc">
int main(int argc, const char * argv[])
</syntaxhighlight>
OCaml.
<syntaxhighlight lang="ocaml">
let main () =
</syntaxhighlight>
Pascal.
<syntaxhighlight lang="pascal">
begin
end.
</syntaxhighlight>
Perl.
<syntaxhighlight lang="perl">
print "Hello, world!\n";
</syntaxhighlight>
Perl 5.10（含）以后版本:
<syntaxhighlight lang="perl">
use 5.010;
say "Hello, world!";
</syntaxhighlight>
Pike.
<syntaxhighlight lang="text">
int main()
</syntaxhighlight>
PL/I.
<syntaxhighlight lang="text">
Test: procedure options(main);
end Test;
</syntaxhighlight>
Prolog.
<syntaxhighlight lang=prolog>
goal
</syntaxhighlight>
Python.
适用于Python 2：
<syntaxhighlight lang="python">
print "Hello, world!"
</syntaxhighlight>
适用于Python 2.6, 2.7, 3：
<syntaxhighlight lang="python">
print("Hello, world!")
</syntaxhighlight>
用彩蛋输出Hello World：
<syntaxhighlight lang="python">
import __hello__
</syntaxhighlight>
REXX.
<syntaxhighlight lang="text">
say "Hello, world!"
</syntaxhighlight>
Ruby.
<syntaxhighlight lang="ruby">
puts "Hello, world!"
</syntaxhighlight>
Rust.
<syntaxhighlight lang="rust">
fn main() {
</syntaxhighlight>
Scheme.
<syntaxhighlight lang="scheme">
</syntaxhighlight>
sed.
（需要至少一行输入）
<syntaxhighlight lang="text">
sed -ne '1s/.*/Hello, world!/p'
</syntaxhighlight>
Seed7.
<syntaxhighlight lang="text">
$ include "seed7_05.s7i";
</syntaxhighlight>
Smalltalk.
<syntaxhighlight lang="smalltalk">
Transcript show: 'Hello, world!'
</syntaxhighlight>
SNOBOL.
<syntaxhighlight lang="text">
END
</syntaxhighlight>
SQL.
第一种.
<syntaxhighlight lang="sql">
create table MESSAGE (TEXT char(15));
insert into MESSAGE (TEXT) values ('Hello, world!');
select TEXT from MESSAGE;
drop table MESSAGE;
</syntaxhighlight>
第二种.
<syntaxhighlight lang="sql">
select 'hello, world';
</syntaxhighlight>
第三种.
<syntaxhighlight lang="sql">
print 'hello,world!'
</syntaxhighlight>
Swift.
适用于Swift 1.x：
适用于Swift 2.x, 3：
Tcl.
<syntaxhighlight lang="tcl">
puts "Hello, world!"
</syntaxhighlight>
TScript.
<syntaxhighlight lang="text">
? "Hello, world!"
</syntaxhighlight>
Turing.
<syntaxhighlight lang="text">
put "Hello, world!"
</syntaxhighlight>
Unix shell脚本.
程序中的/bin/sh可改为您使用的shell
<syntaxhighlight lang="bash">
echo 'Hello, world!'
</syntaxhighlight>
图形用户界面.
AppleScript.
<syntaxhighlight lang="AppleScript">
display dialog "Hello, world!"
</syntaxhighlight>
或者：
<syntaxhighlight lang="AppleScript">
display alert "Hello, world!"
</syntaxhighlight>
Delphi.
<syntaxhighlight lang="delphi">
program HelloWorld;
uses
begin
end.
</syntaxhighlight>
Nuva.
<syntaxhighlight lang="text">
</syntaxhighlight>
Visual Basic.
<syntaxhighlight lang=vb>
Sub Main()
End Sub
</syntaxhighlight>
Visual FoxPro.
<syntaxhighlight lang="visualfoxpro">
? "Hello, world!"
</syntaxhighlight>
X11.
用一个程序
<syntaxhighlight lang="text">
xmessage 'Hello, world!'
</syntaxhighlight>
使用Qt
<syntaxhighlight lang="cpp">
int main(int argc, char *argv[])
</syntaxhighlight>
C 和 GTK+
<syntaxhighlight lang="C">
int main(int argc, char * args[])
</syntaxhighlight>
用C++和gtkmm 2
<syntaxhighlight lang=cpp>
using namespace std;
class HelloWorld : public Gtk::Window 
public:
protected:
};
HelloWorld::HelloWorld() : m_button("Hello, world!")
void HelloWorld::on_button_clicked() 
int main（int argc, char *argv[]）
</syntaxhighlight>
Java.
<syntaxhighlight lang="java">
import java.awt.*;
import java.awt.event.*;
public class HelloFrame extends Frame 
</syntaxhighlight>
Java Applet.
Java Applet用于HTML文件。
HTML代码：
<syntaxhighlight lang="html4strict">
<html>
<head>
<title>Hello World</title>
</head>
<body>
HelloWorld Program says:
<applet code="HelloWorld.class" width="600" height="100">
</applet>
</body>
</html>
</syntaxhighlight>
Java代码：
<syntaxhighlight lang=java>
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet 
</syntaxhighlight>
JavaScript.
JavaScript是一种脚本语言。最广泛用于HTML文件中，也可以用在其它宿主环境下，比如Microsoft® Windows® 脚本宿主（WSH）和一些web服务环境。
用于HTML中： 
<syntaxhighlight lang="javascript">
// 弹出对话框
alert("Hello, World!");
// 在页面上显示
document.write("Hello, World!");
</syntaxhighlight>
用于WSH中：
<syntaxhighlight lang="javascript">WScript.Echo("Hello, World!");</syntaxhighlight>
作为服务器端（Node.js）：启动后，需要在浏览器中访问“http://127.0.0.1:8000/”查看。
<syntaxhighlight lang="javascript">
const http = require('http');
http.createServer((request, response) => {
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
</syntaxhighlight>
PostScript.
PostScript是一种专门用来创建图像的语言，常用于打印机。 
<syntaxhighlight lang=text>
/font /Courier findfont 24 scalefont
font setfont
100 100 moveto
(Hello World!) show
showpage
</syntaxhighlight>
SPARQL.
<syntaxhighlight lang="sparql">
SELECT ?h WHERE { 
</syntaxhighlight>
XAML.
<syntaxhighlight lang="xml">
</syntaxhighlight>
接著使用 C# 建置
<syntaxhighlight lang="csharp">
</syntaxhighlight>
服务器端.
以下为Web服务端示例程序，程序启动后，需要用浏览器访问特定地址来查看结果。
ASP.
<syntaxhighlight lang="asp"><% Response.Write("Hello, world!") %></syntaxhighlight>
<syntaxhighlight lang="asp"><%= "Hello, world!" %></syntaxhighlight>
HTML.
<syntaxhighlight lang="html4strict">
Hello World
<html>
<head>
</head>
<body>
Hello World
</body>
</html>
</syntaxhighlight>
Go.
<syntaxhighlight lang="go">
package main
import (
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
func main() {
</syntaxhighlight>
JSP.
<syntaxhighlight lang="java">
</syntaxhighlight>
或者简单地写成：
<syntaxhighlight lang="java">
<%="Hello, world!"%>
</syntaxhighlight>
JavaScript.
以下为Node.js环境：
<syntaxhighlight lang="javascript">
const http = require('http');
http.createServer((request, response) => {
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
</syntaxhighlight>
PHP.
以下代码既可以作为服务器端运行，显示在用户浏览器上，也可以在终端中直接运行，输出到终端中：
<syntaxhighlight lang="php">
<?php
</syntaxhighlight>
或者
<syntaxhighlight lang="php"><?= "Hello World!"?></syntaxhighlight>