A "hello world" program is a computer program that prints out "Hello, world!" on a display device. It is used in many introductory tutorials for teaching a programming language and many students use it as their first programming experience in a language.
Such a program is typically one of the simplest programs possible in a computer language. Some are surprisingly complex, especially in some graphical user interface (GUI) contexts. Some others are very simple, however, especially those which rely heavily on a particular command line interpreter ("shell") to perform the actual output. In many embedded systems, the text may be sent to a one or two-line liquid crystal display (LCD) (and in yet other systems, a simple LED being turned on may substitute for "Hello world!").
A "hello world" program can be a useful sanity test to make sure that a language's compiler, development environment, and run-time environment are correctly installed. Configuring a complete programming toolchain from scratch to the point where even trivial programs can be compiled and run may involve substantial amounts of work. For this reason, a simple program is used first when testing a new tool chain.
While small test programs existed since the development of programmable computers, the tradition of using the phrase "Hello world!" as the test message was influenced by an example program in the book The C Programming Language, by Brian Kernighan and Dennis Ritchie, published in 1978. The example program from that book prints "hello, world" (i.e., no capital letters, no exclamation sign; those have entered the tradition later). The book had inherited the program from a 1974 Bell Laboratories internal memorandum by Kernighan —Programming in C: A Tutorial— which shows the first known version of the program:
main( ) {
printf("hello, world");
}
However, the first known instance of the usage of the words "hello" and "world" together in computer literature is in A Tutorial Introduction to the Language B, by Brian Kernighan, 1973. [1]
There are many variations on the punctuation and casing of the phrase, and the examples on this page print out several of these variations. Variations include the presence or lack of the comma and exclamation mark, and the capitalisation of the 'H', both 'H' and 'W', or neither. The most commonly accepted variation, despite not being the original text, is "Hello, world!" Some languages are forced to implement different forms, such as "HELLO WORLD!," on systems that only support capital letters, while many "hello world" programs in esoteric languages print out a slightly modified string. "Hello world" programs also normally print a newline character or character sequence (either ASCII-10 or 13,10).
A collection of "hello world" programs written in various computer languages can serve as a very simple "Rosetta Stone" to assist in learning and comparing the languages. Keep in mind, however, that unless assembly language or similar very low-level (hardware-near) languages are involved, not much "computing" (calculation) is usually exhibited.
Here are some examples in different languages:
|
Contents |
1.1 ABC
1.2 Ada
1.3 ALGOL 68
1.4 AmigaE
1.5 APL
1.6 Assembly language
1.6.1 Accumulator-only architecture: DEC PDP-8, PAL-III assembler
1.6.2 First successful µP/OS combinations: Intel 8080/Zilog Z80, CP/M, RMAC assembler
1.6.3 Accumulator + index register machine: MOS Technology 6502, CBM KERNAL, ca65 assembler
1.6.4 Accumulator/Index microcoded machine: Data General Nova, RDOS
1.6.5 Expanded accumulator machine: Intel x86, DOS, TASM
1.6.6 Expanded accumulator machine: Intel x86, Windows, FASM
1.6.7 Expanded accumulator machine: Intel x86, Linux, GAS
1.6.8 General-purpose fictional computer: MIX, MIXAL
1.6.9 General-purpose fictional computer: MMIX, MMIXAL
1.6.10 General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11
1.6.11 CISC on advanced multiprocessing OS: DEC VAX, VMS, MACRO-32
1.6.12 RISC processor: ARM, RISC OS, BBC BASIC's in-line assembler
1.7 AWK
1.8 BASIC
1.9 BCPL
1.10 BLISS
1.11 boo
1.12 Casio fx-7950
1.13 C
1.14 C#
1.15 C++
1.16 C++, Managed
1.17 ColdFusion (CFM)
1.18 COMAL
1.19 CIL
1.20 Clean
1.21 CLIST
1.22 Clipper
1.23 COBOL
1.24 Common Lisp
1.25 D
1.26 DCL batch
1.27 Dylan
1.28 Ed and Ex (Ed extended)
1.29 Eiffel
1.30 Erlang
1.31 Euphoria
1.32 F#
1.33 Factor
1.34 Focus
1.35 Forte TOOL
1.36 Forth
1.37 FORTRAN
1.38 Frink
1.39 Gambas
1.40 Game Maker
1.41 Haskell
1.42 Heron
1.43 HP-41 & HP-42S
1.44 HyperTalk (Apple HyperCard's scripting language)
1.45 IDL
1.46 Inform
1.47 Io
1.48 Iptscrae
1.49 Java
1.50 JVM
1.51 Kogut
1.52 Logo
1.53 Lua
1.54 M (MUMPS)
1.55 Macsyma, Maxima
1.56 Maple
1.57 Mathematica
1.58 MATLAB
1.59 Max
1.60 Modula-2
1.61 MS-DOS batch
1.62 MUF
1.63 Natural
1.64 Ncurses
1.65 Oberon
1.66 Objective C
1.67 OCaml
1.68 OPL
1.69 OPS5
1.70 Pascal
1.71 Perl
1.72 PHP
1.73 Pike
1.74 PL/SQL
1.75 PL/I
1.76 POP-11
1.77 POV-Ray
1.78 Processing
1.79 Prolog
1.80 Python
1.81 REXX, NetRexx, and Object REXX
1.82 RPL
1.83 Ruby
1.84 SAS
1.85 Sather
1.86 Scala
1.87 Scheme
1.88 sed
1.89 Self
1.90 Simula
1.91 Smalltalk
1.92 SML
1.93 SNOBOL
1.94 Span
1.95 SPARK
1.96 SPITBOL
1.97 SQL
1.98 STARLET
1.99 TACL
1.100 Tcl (Tool command language)
1.101 Turing
1.102 TSQL
1.103 UNIX-style shell
|
WRITE "Hello, World!"
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line ("Hello, world!");
end Hello;
For explanation see wikibooks:Programming:Ada:Basic.
begin
print(("Hello, World!", newline))
end
or using the compact notation:
( print(("Hello, World!", newline)) )
PROC main()
WriteF('Hello, World!')
ENDPROC
'Hello World'
Accumulator-only architecture: DEC PDP-8, PAL-III assembler
See the example section of the PDP-8 article.
First successful µP/OS combinations: Intel 8080/Zilog Z80, CP/M, RMAC assembler
bdos equ 0005H ; BDOS entry point
start: mvi c,9 ; BDOS function: output string
lxi d,msg$ ; address of msg
call bdos
ret ; return to CCP
msg$: db 'Hello, world!$'
end start
Accumulator + index register machine: MOS Technology 6502, CBM KERNAL, ca65 assembler
MSG: .ASCIIZ "Hello, world!"
LDX #0
@LP: LDA MSG,X ; load character
JSR $FFD2 ; chrout
INX
BNE @LP
RTS
See the example section of the Nova article.
Expanded accumulator machine: Intel x86, DOS, TASM
MODEL SMALL
IDEAL
STACK 100H
DATASEG
MSG DB 'Hello, world!', 13, '$'
CODESEG
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
;Assumes that enviromnent variable %fasminc% is set
format PE GUI 4.0
include '%fasminc%\win32a.inc'
section '.code' code readable executable
invoke MessageBox,0,hellomsg,hellolb,MB_OK+MB_ICONINFORMATION
invoke ExitProcess,0
section '.data' data readable writable
hellomsg db 'Hello, World!',0
hellolb db 'Hello World',0
data import
library user32,'user32.dll',kernel32,'kernel32.dll'
include '%fasminc%\apia\user32.inc'
include '%fasminc%\apia\kernel32.inc'
end data
.data
msg:
.ascii "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
General-purpose fictional computer: MIX, MIXAL
TERM EQU 19 console device no. (19 = typewriter)
ORIG 1000 start address
START OUT MSG(TERM) output data at address MSG
HLT halt execution
MSG ALF "HELLO"
ALF " WORL"
ALF "D "
END START end of program
General-purpose fictional computer: MMIX, MMIXAL
Main GETA $255,string get the address of the string in register 255
TRAP 0,Fputs,StdOut put the string pointed to by register 255 to file StdOut
string BYTE "Hello, world!",#a,0 string to be printed (#a is newline and 0 terminates the string)
TRAP 0,Halt,0 end process
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 on advanced multiprocessing OS: DEC VAX, VMS, MACRO-32
.title hello
.psect data, wrt, noexe
chan: .blkw 1
iosb: .blkq 1
term: .ascid "SYS$OUTPUT"
msg: .ascii "Hello, world!"
len = . - msg
.psect code, nowrt, exe
.entry hello, ^m<>
; Establish a channel for terminal I/O
$assign_s devnam=term, -
chan=chan
blbc r0, end
; Queue the I/O request
$qiow_s chan=chan, -
func=#io$_writevblk, -
iosb=iosb, -
p1=msg, -
p2=#len
; Check the status and the IOSB status
blbc r0, end
movzwl iosb, r0
; Return to operating system
end: ret
.end hello
RISC processor: ARM, RISC OS, BBC BASIC's in-line assembler
.program
ADR R0,message
SWI "OS_Write0"
SWI "OS_Exit"
.message
DCS "Hello, world!"
DCB 0
ALIGN
or the even smaller version (from qUE);
SWI"OS_WriteS":EQUS"Hello, world!":EQUB0:ALIGN:MOVPC,R14
BEGIN { print "Hello, world!" }
The following example works for any ANSI/ISO-compliant BASIC implementation, as well as most implementations built into or distributed with microcomputers in the 1970s and 1980s (usually some variant of Microsoft BASIC).
10 PRINT "Hello, world!"
20 END
Such implementations of BASIC could also execute instructions in an immediate mode when line numbers are omitted. The following examples works without requiring a RUN instruction.
PRINT "Hello, world!"
? "Hello, world!"
Later implementations of BASIC allowed greater support for structured programming and did not require line numbers for source code. The following example works when RUN for the vast majority of modern BASICs.
PRINT "Hello, world!"
END
Again the "End" statement is optional in many BASICs.
On TI calculators of the TI-80 through TI-86 range:
:Disp "HELLO, WORLD!" or :Output(1,1,"HELLO, WORLD!")
Or simply
:"HELLO, WORLD!"
On TI-89/TI-92 calculators:
:hellowld()
:Prgm
:Disp "Hello, world!"
:EndPrgm
sub main
print "Hello, World"
end sub
To output to the debug console:
Debug.Print "Hello, world!"
To output a message box to the user:
VBA.Interaction.MsgBox "Hello, world!"
GET "LIBHDR"
LET START () BE
$(
WRITES ("Hello, world!*N")
$)
%TITLE 'HELLO_WORLD'
MODULE HELLO_WORLD (IDENT='V1.0', MAIN=HELLO_WORLD,
ADDRESSING_MODE (EXTERNAL=GENERAL)) =
BEGIN
LIBRARY 'SYS$LIBRARY:STARLET';
EXTERNAL ROUTINE
LIB$PUT_OUTPUT;
GLOBAL ROUTINE HELLO_WORLD =
BEGIN
LIB$PUT_OUTPUT(%ASCID %STRING('Hello World!'))
END;
END
ELUDOM
print "Hello, world!"
This program will work on the fx-9750 graphing calculator and compatibles.
"HELLO WORLD"↵
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
using System;
class HelloWorldApp
{
public static void Main()
{
Console.WriteLine("Hello, world!");
}
}
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
#using <mscorlib.dll>
using namespace System;
int wmain()
{
Console::WriteLine("Hello, world!");
return 0;
}
<cfoutput>
Hello, world!
</cfoutput>
PRINT "Hello, World!"
.method public static void Main() cil managed
{
.entrypoint
.maxstack 8
ldstr "Hello, world!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
module hello
Start = "Hello, world"
PROC 0
WRITE Hello, World!
@1,1 say "Hello World!"
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
(format t "Hello world!~%")
or
(write-line "Hello World!")
import std.stdio;
void main()
{
writefln("Hello, world!");
}
$ write sys$output "Hello, world!"
module: hello
format-out("Hello, world!\n");
Ed and Ex (Ed extended)
a
hello world!
.
p
or like so:
echo -e 'a\nhello world!\n.\np'|ed
echo -e 'a\nhello world!\n.\np'|ex
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
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("Hello, world!\n").
puts(1, "Hello, world!")
print_string "Hello world";
print_newline()
"Hello world" print
-TYPE Hello World
Forte TOOL
begin TOOL HelloWorld;
includes Framework;
HAS PROPERTY IsLibrary = FALSE;
forward Hello;
-- START CLASS DEFINITIONS
class Hello inherits from Framework.Object
has public method Init;
has property
shared=(allow=off, override=on);
transactional=(allow=off, override=on);
monitored=(allow=off, override=on);
distributed=(allow=off, override=on);
end class;
-- END CLASS DEFINITIONS
-- START METHOD DEFINITIONS
------------------------------------------------------------
method Hello.Init
begin
super.Init();
task.Part.LogMgr.PutLine('HelloWorld!');
end method;
-- END METHOD DEFINITIONS
HAS PROPERTY
CompatibilityLevel = 0;
ProjectType = APPLICATION;
Restricted = FALSE;
MultiThreaded = TRUE;
Internal = FALSE;
LibraryName = 'hellowor';
StartingMethod = (class = Hello, method = Init);
end HelloWorld;
." Hello, world!" CR
PROGRAM HELLO
PRINT *, 'Hello, world!'
END
println["Hello, world!"]
See also GUI section.
PUBLIC SUB Main()
Print "Hello, world!"
END
In the draw event of some object:
draw_text(x,y,"Hello World")
Or to show a splash screen message:
show_message("Hello World")
module Main (main) where
main = putStr "Hello World\n"
or
main = putStr "Hello World\n"
program HelloWorld;
functions {
_main() {
print_string("Hello, world!");
}
}
end
(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)
01 LBLTHELLO
02 THELLO, WORLD
03 PROMPT
put "Hello world"
print,"Hello world!"
[ Main;
print "Hello, world!^";
];
"Hello world!" print
or
write("Hello world!\n")
Iptscrae
ON ENTER {
"Hello, " "World!" & SAY
}
See also GUI section.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
(disassembler output of javap -c Hello.class)
public class Hello extends java.lang.Object {
public Hello();
public static void main(java.lang.String[]);
}
Method Hello()
0 aload_0
1 invokespecial #1 <Method java.lang.Object()>
4 return
Method void main(java.lang.String[])
0 getstatic #2 <Field java.io.PrintStream out>
3 ldc #3 <String "Hello, world!">
5 invokevirtual #4 <Method void println(java.lang.String)>
8 return
WriteLine "Hello, world!"
print [hello world!]
or
pr [Hello World!]
In mswlogo only
messagebox [Hi] [Hello World]
print "Hello, world!"
W "Hello, world!"
print("Hello, world!")$
print("Hello, World!");
Print["Hello World"]
disp('Hello World')
max v2;
#N vpatcher 10 59 610 459;
#P message 33 93 63 196617 Hello world!;
#P newex 33 73 45 196617 loadbang;
#P newex 33 111 31 196617 print;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P pop;
MODULE Hello;
FROM Terminal2 IMPORT WriteLn; WriteString;
BEGIN
WriteString("Hello, world!");
WriteLn;
END Hello;
(with the standard command.com interpreter. The @ symbol is optional and prevents the system from repeating the command before executing it. The @ symbol must be omitted on versions of MS-DOS prior to 3.0.)
@echo Hello, world!
: main
me @ "Hello, world!" notify
;
Natural
WRITE "Hello, World!"
END
#include <ncurses.h>
int main()
{
initscr();
printw("Hello, world!");
refresh();
getch();
endwin();
return 0;
}
MODULE Hello;
IMPORT Oberon, Texts;
VAR W: Texts.Writer;
PROCEDURE World*;
BEGIN
Texts.WriteString(W, "Hello World!");
Texts.WriteLn(W);
Texts.Append(Oberon.Log, W.buf)
END World;
BEGIN
Texts.OpenWriter(W)
END Hello.
Using the C library
#import <stdio.h>
//An object-oriented version.
@interface Hello : Object
{
const char str[] = "Hello world";
}
- (id) hello (void);
@end
@implementation Hello
- (id) hello (void)
{
printf("%s\n", str);
}
@end
int main(void)
{
Hello *h = [Hello new];
[h hello];
[h free];
return 0;
}
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSLog(@"Hello, World!");
return 0;
}
print_endline "Hello world!"
See also GUI section.
PROC hello:
PRINT "Hello, World"
ENDP
(object-class request
^action)
(startup
(strategy MEA)
(make request ^action hello)
)
(rule hello
(request ^action hello)
-->
(write |Hello World!| (crlf))
)
Program Hello;
begin
WriteLn('Hello, world!');
end.
print "Hello, world!\n";
(This is the first example of Learning Perl; the semicolon is optional)
<?php
echo 'Hello, world!\n';
?>
or
<?='Hello World!\n'?>
but this is more recommended
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?='Hello, World!'?>
</body>
</html>
int main() {
write("Hello, world!\n");
return 0;
}
procedure print_hello_world as
dbms_output.enable(1000000);
dbms_output.put_line("Hello World!");
end print_hello_world;
Test: proc options(main) reorder;
put skip edit('Hello, world!') (a);
end Test;
'Hello world' =>
#include "colors.inc"
camera {
location <3, 1, -10>
look_at <3,0,0>
}
light_source { <500,500,-1000> White }
text {
ttf "timrom.ttf" "Hello world!" 1, 0
pigment { White }
}
println("Hello world!");
write('Hello world'),nl.
print "Hello, world!"
REXX, NetRexx , and Object REXX
say "Hello, world!"
See also GUI section.
(On Hewlett-Packard HP-28 , HP-48 and HP-49 series graphing calculators.)
<<
CLLCD
"Hello, World!" 1 DISP
0 WAIT
DROP
>>
See also GUI section.
puts "Hello, world!"
data _null_;
put 'Hello World!';
run;
class HELLO_WORLD is
main is
#OUT+"Hello World\n";
end;
end;
object HelloWorld with Application {
Console.println("Hello, world!");
}
(display "Hello, world!")
(newline)
(note: requires at least one line of input)
sed -ne '1s/.*/Hello, world!/p'
'Hello, World!' print.
BEGIN
OutText("Hello World!");
OutImage;
END
Transcript show: 'Hello, world!'; cr
print "Hello, world!\n";
OUTPUT = "Hello, world!"
END
class Hello {
static public main: args {
Console << "Hello World!\n";
}
}
with Spark_IO;
--# inherit Spark_IO;
--# main_program;
procedure Hello_World
--# global in out Spark_IO.Outputs;
--# derives Spark_IO.Outputs from Spark_IO.Outputs;
is
begin
Spark_IO.Put_Line (Spark_IO.Standard_Output, "Hello, world!", 0);
end Hello_World;
OUTPUT = "Hello, world!"
END
CREATE TABLE message (text char(15));
INSERT INTO message (text) VALUES ('Hello, world!');
SELECT text FROM message;
DROP TABLE message;
or (e.g. Oracle dialect)
SELECT 'Hello, world!' FROM dual;
or (for Oracle's PL/SQL proprietary procedural language)
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
DBMS_OUTPUT.PUT_LINE('Hello World, from PL/SQL');
END;
or (e.g. MySQL or PostgreSQL dialect)
SELECT 'Hello, world!';
or (e.g. T-SQL dialect)
PRINT 'Hello, world!'
or (for KB-SQL dialect)
select Null from DATA_DICTIONARY.SQL_QUERY
FOOTER or HEADER or DETAIL or FINAL event
write "Hello, world!"
STARLET
RACINE: HELLO_WORLD.
NOTIONS:
HELLO_WORLD : ecrire("Hello, world!").
TACL
#OUTPUT Hello, world!
Tcl (Tool command language)
See also GUI section.
puts "Hello, world!"
put "Hello, world!"
Declare @Output varchar(16)
Set @Output='Hello, world!'
Select @Output
or, simpler variations:
Select 'Hello, world!'
Print 'Hello, world!'
echo 'Hello, world!'
or
printf 'Hello, world!\n'
or for a curses interface:
dialog --msgbox "Hello, world!" 0 0
Graphical user interfaces (GUIs)
trace ("hello, world!")
display dialog "Hello, world!"
Or to have the OS synthesize it and literally say "hello world!" (with no comma, as that would cause the synthesizer to pause)
say "Hello world!"
#import <Cocoa/Cocoa.h>
@interface hello : NSObject {
}
@end
@implementation hello
-(void)awakeFromNib
{
NSBeep(); // we don't need this but it's conventional to beep
// when you show an alert
NSRunAlertPanel(@"Message from your Computer", @"Hello, world!", @"Hi!",
nil, nil);
}
@end
ShowMessage("Hello, world!");
FLTK2 (in C++)
#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/run.h>
using namespace fltk;
int main(int argc, char **argv)
{
Window *window = new Window(300, 180);
window->begin();
Widget *box = new Widget(20, 40, 260, 100, "Hello, World!");
box->box(UP_BOX);
box->labelfont(HELVETICA_BOLD_ITALIC);
box->labelsize(36);
box->labeltype(SHADOW_LABEL);
window->end();
window->show(argc, argv);
return run();
}
See also TUI section.
PUBLIC SUB Main()
Message.Info("Hello, world!")
END
#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);
return 0;
}
using Gtk;
using GtkSharp;
using System;
class Hello {
static void Main()
{
Application.Init ();
Window window = new Window ("helloworld");
window.Show();
Application.Run ();
}
}
include gtk2/wrapper.e
Info(NULL,"Hello","Hello World!")
See also TUI section.
import javax.swing.JOptionPane;
public class Hello {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello, world!");
}
}
- Java applets work in conjunction with HTML files.
<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
HelloWorld Program says:
<APPLET CODE="HelloWorld.class" WIDTH=600 HEIGHT=100>
</APPLET>
</BODY>
</HTML>
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello, world!", 100, 50);
}
}
- JavaScript (an implementation of ECMAScript) is a client-side scripting language used in HTML files. The following code can be placed in any HTML file:
<script type="text/javascript"><!--
function helloWorld()
{
alert("Hello, world!");
}
//--></script>
<a href="#" onclick="helloWorld(); return false;">Hello World Example</a>
- An easier method uses JavaScript implicitly, directly calling the reserved alert function. Cut and paste the following line inside the <body> .... </body> HTML tags.
<a href="#" onclick="alert('Hello, world!'); return false;">Hello World Example
</a>
- 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!');
- There is an almost infinite number of ways to do it:
javascript:document.write('Hello, world!\n');
See also TUI section.
(On Psion Series 3 and later compatible PDAs.)
PROC guihello:
ALERT("Hello, world!","","Exit")
ENDP
or
PROC hello:
dINIT "Window Title"
dTEXT "","Hello World"
dBUTTONS "OK",13
DIALOG
ENDP
#include <qapplication.h>
#include <qpushbutton.h>
#include <qwidget.h>
#include <iostream>
class HelloWorld : public QWidget
{
Q_OBJECT
public:
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(argc, argv);
HelloWorld helloWorld;
app.setMainWidget(&helloWorld);
helloWorld.show();
return app.exec();
}
MsgBox "Hello, world!"
See also TUI section.
(On Hewlett-Packard HP-48G and HP-49G series calculators.)
<< "Hello, World!" MSGBOX >>
Hello ()
TEXT "Hello, world!"
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
public class SWTHello {
public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell(display);
RowLayout layout = new RowLayout();
layout.justify = true;
layout.pack = true;
shell.setLayout(layout);
shell.setText("Hello, World!");
Label label = new Label(shell, SWT.CENTER);
label.setText("Hello, World!");
shell.pack();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
See also TUI section.
label .l -text "Hello, world!"
pack .l
Sub Main()
MsgBox "Hello, world!"
End Sub
#include <windows.h>
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)>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;
}
Or, much more simply:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
MessageBox(NULL, "Hello, world!", "", MB_OK);
return 0;
}
WScript.Echo "Hello, world!"
See also TUI section.
require 'wxruby'
class HelloWorldApp < Wx::App
def on_init
ourFrame = Wx::Frame.new(nil, -1, "Hello, world!").show
ourDialogBox = Wx::MessageDialog.new(ourFrame, "Hello, world!", "Information:", \
Wx::OK|Wx::ICON_INFORMATION).show_modal
end
end
HelloWorldApp.new.main_loop
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box align="center" pack="center" flex="1">
<description>Hello, world</description>
</box>
</window>
Esoteric programming languages
See: Hello world program in esoteric languages
Document formats
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
The following sequence of characters, expressed as binary numbers (with cr/nl as above, and the same ordering of bytes):
00–07: 01001000 01100101 01101100 01101100 01101111 00101100 00100000 01110111
08–0E: 01101111 01110010 01101100 01100100 00100001 00001101 00001010
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
(Using UTF-8 character set.)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, world!</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
(simple)
<html><body>
<h1>Hello, world!<p>
</body></html>
<html> and <body>-tags are not necessary for informal testing, <h1> should end with </h1> or <p>. You could even use the following
<pre>Hello, World!</pre>
or simple write it as text without tags.
HTML 4.01 Strict
(full)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
(Using UTF-8 character set.)
<?xml version="1.0" encoding="utf-8">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8"
doctype-system="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd"
doctype-pubilc="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:template match="/">
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World
</body>
</html>
</xsl:template>
</xsl:stylesheet>
% Displays on console.
(Hello world!) =
% Displays as page output.
/Courier findfont
24 scalefont
setfont
100 100 moveto
(Hello world!) show
showpage
{\rtf1\ansi\deff0
{\fonttbl {\f0 Courier New;}}
\f0\fs20 Hello, world!
}
\font\HW=cmr10 scaled 3000
\leftline{\HW Hello World}
\bye
See also
External links