以下是用不同语言写成的Hello World程序的列表:
Hello World的正确输出示范
clear
? "hello, world!"
trace("Hello, world!");
with TEXT_IO;
procedure HELLO is
begin TEXT_IO.PUT_LINE ("Hello, world!");end HELLO;
section .data msg db 'Hello, world!',0xA len equ $-msg section .text global _start _start: mov edx,len mov ecx,msg mov ebx,1 mov eax,4 int 0x80 mov ebx,0 mov eax,1 int 0x80.data msg : .string "Hello, world!\n" len = . - msg.text.global _start _start: movl $len, %edx movl $msg, %ecx movl $1 , %ebx movl $4 , %eax int $0x80 movl $0 , %ebx movl $1 , %eax int $0x80
.386 .model flat,stdcall option casemap:none;========================================================== include windows.inc include user32.inc includelib user32.lib include kernel32.inc includelib kernel32.lib;========================================================== .dataszCaption db "A MessageBox!", 0
szText db "Hello, world!", 0
;========================================================== .codestart: invoke MessageBox, NULL, addr szText, addr szCaption, MB_OK invoke ExitProcess, NULL;========================================================== end start[BITS 16]
org 0x7c00
mov ax,cs mov ds,ax mov es,ax call DispStr jmp $;End HearDispStr: mov ax, BootMessage mov bp, ax mov cx, 16;How long is the String mov ax, 0x1301 mov bx, 0x000c mov dl, 0 int 0x10 retBootMessage: db "Hello, world!"
times 510-($-$$) db 0x0
dw 0xaa55; Bootable Mark
<% Response.Write("Hello, world!") %>
或者简单地写成:
<%= "Hello, world!" %>
MsgBox(1,'','Hello, world!')
BEGIN { print "Hello, world!" }
echo 'Hello, world!'或者:
printf 'Hello, world!\n'
传统版 BASIC(例如 GWBASIC):
10 PRINT "Hello, world!"
20 END
或在提示符输入:
? "Hello, world!"
现代版 BASIC(例如 Quick BASIC):
Print "Hello, world!"
以下的语句,在 Quick BASIC 中同样有效:
? "Hello, world!"
GET "LIBHDR" LET START () BE$( WRITES ("Hello, world!*N")$)++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.Print "Hello, world!"
WaitKeyprint "Hello, world!"
#include <stdio.h>int main(void)
{ printf("Hello, world!\n"); return 0;}或者:
#include <stdio.h>int main(void)
{ puts("Hello, world!"); return 0;}
#include <iostream>int main()
{ std::cout << "Hello, world!" << std::endl; return 0;}或者:
#include <iostream>using namespace std;
int main()
{ cout << "Hello, world!" << endl; return 0;}
int main()
{ System::Control::WriteLine("Hello, world!");}class HelloWorldApp
{ static void Main(string[] args) { System.Console.WriteLine("Hello, world!"); }}
或者(仅用于Microsoft Windows)
class HelloWorldApp
{ [DllImport("user32.dll")] static extern MessageBox(string title, string message); public static void Main() { MessageBox(null, "Hello, world!"); }}或者(使用附加的Windows Forms)
using System.Windows.Forms;
class HelloWorldApp
{ public static void Main() { MessageBox.Show("Hello, world!"); }}IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
;直接输出
"Hello world!" ;或者
(format t "Hello world!~%")
@echo Hello, world!
对于MS-DOS 3.0或更低版本:
echo off
clsecho Hello, world!
echo Hello, world!
class HELLO_WORLD
creation makefeature make is local io:BASIC_IO do !!io io.put_string("%N Hello, world!") end -- makeend -- class HELLO_WORLD
-module(hello). -export([hello_world/0]). hello_world() -> io:fwrite("Hello, World!\n").
." Hello, world!" CR
WRITE(*,*) 'Hello, world!' STOP END
<!-- 直接輸出... -->
Hello World<!-- 或者 -->
<html><head><title> Hello World </title>
</head><body>Hello World</body></html>
HPLEASE DO ,1 <- #13DO ,1 SUB #1 <- #238DO ,1 SUB #2 <- #112DO ,1 SUB #3 <- #112DO ,1 SUB #4 <- #0DO ,1 SUB #5 <- #64DO ,1 SUB #6 <- #238DO ,1 SUB #7 <- #26DO ,1 SUB #8 <- #248DO ,1 SUB #9 <- #168DO ,1 SUB #10 <- #24DO ,1 SUB #11 <- #16DO ,1 SUB #12 <- #158DO ,1 SUB #13 <- #52PLEASE READ OUT ,1PLEASE GIVE UP
public class Hello
{ public static void main(String[] args) { System.out.print("Hello, world!"); }}or in tinystruct2.0:
package tinystruct.examples;
import org.tinystruct.AbstractApplication;
import org.tinystruct.Application;
import org.tinystruct.ApplicationException;
import org.tinystruct.system.ApplicationManager;
public class hello extends AbstractApplication {
@Override public void init() { // TODO Auto-generated method stub this.setAction("say", "say"); } @Override public String version() { // TODO Auto-generated method stub return null; } public String say(String words){ System.out.println(words); return words; } /** * @param args * @throws ApplicationException */ public static void main(String[] args) throws ApplicationException { // TODO Auto-generated method stub // Praise to the Lord! ApplicationManager.install(new hello()); // to print 'Hello World' ApplicationManager.call("say/Hello World", null); // Hello World // or... Application app=ApplicationManager.get( hello.class.getName()); app.invoke("say", new Object[]{"<h1>Hello, World!</h1>"}); // <h1>Hello, World!</h1> app.invoke("say", new Object[]{"<h2>Bye!</h2>"}); // <h2>Bye!</h2> // or... // http://localhost:8080/?q=say/Hello World // https://github.com/m0ver/tinystruct2.0 } }<% out.print("Hello, world!");%>
或者简单地写成:
<%="Hello, world!"%>
;直接输出
"hello, world" ;或者
(format t "hello, world~%")
print "Hello, world!"
('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#" `CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@>
Hello[] := Print["Hello World!"] Hello[]
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;endTERM EQU 19 the MIX console device number ORIG 1000 start addressSTART OUT MSG(TERM) output data at address MSG HLT halt executionMSG ALF "MIXAL" ALF " HELL" ALF "O WOR" ALF "LD " END START end of the program<..直接输出..>
Hello, world! <..或者..>
<. // 不带换行 ? "Hello, world!" // 或者 // 带换行 ?? 'Hello, world!'.>#import <Foundation/Foundation.h> int main(int argc, const char * argv[])
{ @autoreleasepool { NSLog(@"Hello, World!"); } return 0;}
let main () =
print_endline "Hello world!";;program Hello;{此行可以省略}
begin writeln('Hello, world!');end.
#!/usr/bin/env perlprint "Hello, world!\n";
Perl 5.10(含)以后版本:
#!/usr/bin/env perluse 5.010;
say "Hello, world!";
<?phpecho 'Hello, world!';//通常使用這個,比 print 少一個字元
print 'Hello, world!';?>或者
<?= "Hello World!"?>
#!/usr/local/bin/pikeint main(){ write("Hello, world!\n"); return 0;}Test: procedure options(main); declare My_String char(20) varying initialize('Hello, world!'); put skip list(My_String);end Test;goal write("hello,world!").适用于Python 2:
#!/usr/bin/env pythonprint "Hello, world!"
适用于Python 3:
#!/usr/bin/env pythonprint("Hello, world!")
say "Hello, world!"#!/usr/bin/rubyputs "Hello, world!"
INIT min:1001Om:"Hello, world!"(display "Hello, world!")
(newline)
主条目:Scratch (编程语言)

(需要至少一行输入)
sed -ne '1s/.*/Hello, world!/p'$ include "seed7_05.s7i"; const proc: main is func begin writeln("Hello, world!"); end func;Transcript show: 'Hello, world!'
TextWindow.WriteLine("Hello, world!")
OUTPUT = "Hello, world!"ENDcreate table MESSAGE (TEXT char(15));
insert into MESSAGE (TEXT) values ('Hello, world!');
select TEXT from MESSAGE;
drop table MESSAGE;
select 'hello, world';
print 'hello,world!'
println("Hello, World!")
#!/usr/local/bin/tclputs "Hello, world!"
? "Hello, world!"put "Hello, world!"程序中的/bin/sh可改为您使用的shell
#!/bin/shecho 'Hello, world!'
#!/usr/bin/bc -qprint "Hello World"quit
#!/usr/bin/env dc[Hello World]p
<includeonly>Hello, World!</includeonly><br/>
program HelloWorld;
uses Dialogs;begin ShowMessage('Hello, World!');end.
<. System.Ui.ShowMessage('Nuva', 'Hello, world!', ['OK']).>MsgBox "Hello, world!"
'或者
Print "Hello, world!"
? "Hello, world!"用一个程序
xmessage 'Hello, world!'使用Qt
#include <QApplication>#include <QLabel> int main(int argc, char *argv[])
{ QApplication app(argc, argv); QLabel label("Hello, world!"); label.show(); return app.exec();}C 和 GTK+
#include <gtk/gtk.h> int main(int argc, char * args[])
{ GtkWidget * win, * label; gtk_init(& argc, & args); label = gtk_label_new("Hello, world!"); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_add(GTK_CONTAINER(win), label); gtk_widget_show_all(); gtk_main(); return 0;}用C++和gtkmm 2
#include <iostream>#include <gtkmm/main.h>#include <gtkmm/button.h>#include <gtkmm/window.h>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::slot(*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);}import java.awt.*;
import java.awt.event.*;
public class HelloFrame extends Frame
{ HelloFrame(String title) { super(title); } 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 []) { 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); }}Java Applet用于HTML文件。
HTML代码:
<html><head><title>Hello World</title>
</head><body>HelloWorld Program says:<applet code="HelloWorld.class" width="600" height="100">
</applet></body></html>Java代码:
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet
{ public void paint(Graphics g) { g.drawString("Hello, world!", 100, 50); }}JavaScript是一种脚本语言。最广泛用于HTML文件中,也可以用在其它宿主环境下,比如Microsoft® Windows® 脚本宿主(WSH)和一些web服务环境。
用于HTML中:
alert("Hello, World!");
//或者
document.write("Hello, World!");
用于WSH中:
WScript.Echo("Hello, World!");
PostScript是一种专门用来创建图像的语言,常用于打印机。
/font /Courier findfont 24 scalefontfont setfont100 100 moveto(Hello World!) showshowpage <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="XAMLSample.Page1" > <Button Click="HelloWorld" Name="Button1">Click Here</Button> </Page>接着使用 C# 建置
using System; using System.Windows; using System.Windows.Controls; namespace XAMLSample { public partial class Page1 : Page { void HelloWorld(object sender, RoutedEventArgs e) { MessageBox.Show("Hello, world!"); } } }