List of hello world programs
From Wikipedia, the free encyclopedia
The following is a list of hello world programs.
Text user interface (Known as TUI, console or line-oriented)
4DOS batch
It should be noted that the 4DOS/4NT batch language is a superset of the MS-DOS batch language.
@echo Hello, world!
4GL - Computer Associates with Ingres/DB
message "Hello, world!" with style = popup;
ABAP - SAP AG
REPORT ZELLO. WRITE 'Hello, world!'.
ABC
WRITE "Hello, world!"
ActionScript
trace("Hello, world!");
Ada
with TEXT_IO; procedure HELLO is begin TEXT_IO.PUT_LINE ("Hello, world!"); end HELLO;
For explanation see wikibooks:Ada Programming:Basic.
ALGOL 68
In the popular upper-case stropping convention for bold words:
BEGIN
print(("Hello, world!", newline))
END
or using prime stropping suitable for punch cards:
'BEGIN'
PRINT(("HELLO, WORLD!", NEWLINE))
'END'
or minimally using the "brief symbol" form of begin and end, and implied newline at program termination:
( print("Hello, world!") )
AmigaE
PROC main()
WriteF('Hello, world!');
ENDPROC
APL
An explicit return function for the Hello World program may be coded as follows (note: TeX fonts are not correct)
- The Del on the first line begins function definition for the program named HWΔPGM. It is a niladic function (no parameters, as opposed to monadic or dyadic) and it will return an explicit result which allows other functions or APL primatives to use the returned value as input.
- The line labled 1 assigns the text vector 'HELLO WORLD!' to the variable R
- The last line is another Del which ends the function definition.
When the function is executed but typing its name the APL interpreter assigns the text vector to the variable R, but since we have not used this value in another function, primitive, or assignment statement the interpreter returns it to the terminal, thus displaying the words on the next line below the function invocation.
The session would look like this
HWΔPGM
HELLO WORLD!
While not a program, if you simply supplied the text vector to the interpreter but did not assign it to a variable it would return it to the terminal as output. Note that user input is automatically indented 6 spaces by the interpreter while results are displayed at the beginning of a new line.
'Hello, World!'
Hello World!
AppleScript
See also GUI section.
return "Hello, world!"
ASP
<% Response.Write("Hello, world!") %>
- or
<% strHelloWorld = "Hello, world!" %> <%= strHelloWorld %>
- or simply:
<%= "Hello, world!" %>
ASP.NET
// in the page behind using C#
public override void OnLoad (EventArgs e)
{
Response.Write("Hello, world!");
}
- or
<% Response.Write("Hello, world!") %>
- or
<% strHelloWorld = "Hello, world!" %> <%= strHelloWorld %>
- or simply:
<%= "Hello, world!" %>
Assembly language
Accumulator-only architecture: DEC PDP-8, PAL-III assembler
See the example section of the PDP-8 article.
First successful uP/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
Popular home computer: ZX Spectrum, Zilog Z80, HiSoft GENS assembler
10 ORG #8000 ; Start address of the routine 20 START LD A,2 ; set the output channel 30 CALL #1601 ; to channel 2 (main part of TV display) 40 LD HL,MSG ; Set HL register pair to address of the message 50 LOOP LD A,(HL) ; De-reference HL and store in A 60 CP 0 ; Null terminator? 70 RET Z ; If so, return 80 RST #10 ; Print the character in A 90 INC HL ; HL points at the next char to be printed 100 JR LOOP 110 MSG DEFM "Hello, world!" 120 DEFB 13 ; carriage return 130 DEFB 0 ; null terminator
Accumulator + index register machine: MOS Technology 6502, CBM KERNAL, ca65 assembler
MSG: .ASCIIZ "Hello, world!"
LDX #$F3
@LP: LDA MSG-$F3,X ; load character
JSR $FFD2 ; CHROUT (KERNAL), output to current output device (screen)
INX
BNE @LP ;
RTS
Accumulator/Index microcoded machine: Data General Nova, RDOS
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
Start:
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 Start
Expanded accumulator machine: Intel x86, Microsoft Windows, FASM
; Example of making 32-bit PE program as raw code and data
format PE GUI
entry start
section '.code' code readable executable
start:
push 0
push _caption
push _message
push 0
call [MessageBox]
push 0
call [ExitProcess]
section '.data' data readable writeable
_caption db 'Win32 assembly program',0
_message db 'Hello, world!',0
section '.idata' import data readable writeable
dd 0,0,0,RVA kernel_name,RVA kernel_table
dd 0,0,0,RVA user_name,RVA user_table
dd 0,0,0,0,0
kernel_table:
ExitProcess dd RVA _ExitProcess
dd 0
user_table:
MessageBox dd RVA _MessageBoxA
dd 0
kernel_name db 'KERNEL32.DLL',0
user_name db 'USER32.DLL',0
_ExitProcess dw 0
db 'ExitProcess',0
_MessageBoxA dw 0
db 'MessageBoxA',0
section '.reloc' fixups data readable discardable
Expanded accumulator machine: Intel x86, Linux, FASM
format ELF executable
entry _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
int 0x80
msg db 'Hello, world!', 0xA
msg_len = $-msg
Expanded accumulator machine: Intel x86, Linux, GAS
.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
string BYTE "Hello, world!",#a,0 string to be printed (#a is newline and 0 terminates the string)
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
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 Amiga: Motorola 68000
xref _LVOCloseLibrary
xref _LVOOpenLibrary
xref _LVOPutStr
; open DOS library
movea.l 4,a6
lea.l dosname(pc),a1
clr.l d0
jsr _LVOOpenLibrary(a6)
movea.l d0,a6
; actual print string
move.l #hellostr,d1
jsr _LVOPutStr(a6)
; close DOS library
movea.l a6,a1
movea.l 4,a6
jsr _LVOCloseLibrary(a6)
rts
dosname dc.b 'dos.library',0
hellostr dc.b 'Hello, world!',10,0
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
Mainframe: IBM z/Architecture series using BAL
HELLO CSECT The name of this program is 'HELLO'
USING *,12 Tell assembler what register we are using
SAVE (14,12) Save registers
LR 12,15 Use Register 12 for this program
WTO 'Hello World' Write To Operator
RETURN (14,12) Return to calling party
END HELLO This is the end of the program
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
RISC processor: MIPS architecture
.data
msg: .asciiz "Hello, world!"
.align 2
.text
.globl main
main:
la $a0,msg
li $v0,4
syscall
jr $ra
AutoHotkey
MsgBox, Hello`, world!
AutoIt
MsgBox(1,'','Hello, world!')
Avenue - Scripting language for ArcView GIS
MsgBox("Hello, world!","aTitle")
AWK
BEGIN { print "Hello, world!" }
B
This is the first known hello world program ever written:[1]
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
Bash or sh
echo 'Hello, world!'
or
printf 'Hello, world!\n'
BASIC
General
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
Note that the "END" statement is optional in many implementations of BASIC.
Some implementations could also execute instructions in an immediate mode when line numbers are omitted. The following examples work 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.
DarkBASIC
PRINT "HELLO WORLD" TEXT 0,0,"Hello, world!" WAIT KEY
PBASIC
DEBUG "Hello, world!", CR
or, the typical microcontroller Hello World program equivalent with the only output device present being a light-emitting diode (LED) (in this case attached to the seventh output pin):
DO
HIGH 7 'Make the 7th pin go high (turn the LED on)
PAUSE 500 'Sleep for half a second
LOW 7 ' Make the 7th pin go low (turn the LED off)
PAUSE 500 'Sleep for half a second
LOOP
END
StarOffice/OpenOffice Basic
sub main
print "Hello, world!"
end sub
TI-BASIC
On TI calculators of the TI-80 through TI-86 range:
:Disp "HELLO, WORLD! (note the optional ending quotes) or :"HELLO, WORLD! (only works if on last line of program) or :Output(X,Y,"HELLO, WORLD! or :Text(X,Y,"HELLO, WORLD! (writes to the graph rather than home screen) or :Text(-1,X,Y,"HELLO, WORLD! (only on the 83+ and higher)
On TI-89/TI-89 Titanium/TI-92(+)/Voyage 200 calculators:
:hellowld() :Prgm :Disp "Hello, world!" :EndPrgm
Visual Basic .NET
Module HelloWorldApp
Sub Main()
System.Console.WriteLine("Hello, world!")
End Sub
End Module
or, defined differently,
Class HelloWorldApp
Shared Sub Main()
System.Console.WriteLine("Hello, world!")
End Sub
End Class
bc
"Hello, world!"
or, with the newline
print "Hello, world!\n"
BCPL
GET "LIBHDR"
LET START () BE
$(
WRITES ("Hello, world!*N")
$)
Befunge
v >v"Hello world!"0< ,: ^_25*,@
BLISS
%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
boo
See also GUI Section.
print "Hello, world!"
Boolfuck
;;;+;+;;+;+; +;+;+;+;;+;;+; ;;+;;+;+;;+; ;;+;;+;+;;+; +;;;;+;+;;+; ;;+;;+;+;+;; ;;;;;+;+;; +;;;+;+;;;+; +;;;;+;+;;+; ;+;+;;+;;;+; ;;+;;+;+;;+; ;;+;+;;+;;+; +;+;;;;+;+;; ;+;+;+;
Brainfuck
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Casio FX-9750
This program will work on the fx-9750 graphing calculator and compatibles.
"HELLO WORLD"↵
C/AL - MBS Navision
OBJECT Codeunit 50000 HelloWorld
{
PROPERTIES
{
OnRun=BEGIN
MESSAGE(Txt001);
END;
}
CODE
{
VAR
Txt001@1000000000 : TextConst 'ENU=Hello, world';
BEGIN
{
Hello World in C/AL (Microsoft Business Solutions-Navision)
}
END.
}
}
C
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("Hello, world!\n");
return 0;
}
or
#include <stdio.h>
int main(int argc, char* argv[])
{
puts("Hello, world!");
return 0;
}
Ch
The above C code can run in Ch as examples. The simple one in Ch is:
printf("Hello, world!\n");
C#
See also GUI Section.
class HelloWorldApp
{
static void Main()
{
System.Console.WriteLine("Hello, world!");
}
}
Chrome
namespace HelloWorld; interface type HelloClass = class public class method Main; end; implementation class method HelloClass.Main; begin System.Console.WriteLine('Hello, world!'); end; end.
C++
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
- or
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
C++/CLI
int main()
{
System::Console::WriteLine("Hello, world!");
}
C++, Managed (.NET)
#using <mscorlib.dll>
using namespace System;
int wmain()
{
Console::WriteLine("Hello, world!");
}
LPC
void create()
{
write("Hello, world!\n");
}
ColdFusion (CFM)
<cfoutput>Hello, world!</cfoutput>
COMAL
PRINT "Hello, world!"
CIL
.method public static void Main() cil managed
{
.entrypoint
.maxstack 1
ldstr "Hello, world!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
Clean
module hello Start = "Hello, world!"
CLIST
PROC 0 WRITE Hello, world!
Clipper
? "Hello, world!"
CLU
start_up = proc ()
po: stream := stream$primary_output ()
stream$putl (po, "Hello, world!")
end start_up
COBOL
identification division.
program-id. hello-world.
procedure division.
display "Hello, world!"
stop run.
The above is a very abbreviated and condensed version, which omits the author name and source and destination computer types.
D
import std.stdio ;
void main () {
writef("Hello, world!");
}
D++
function main()
{
screenput "Hello, world!";
}
DC an arbitrary precision calculator
[Hello, world!]p
DCL batch
$ write sys$output "Hello, world!"
DOLL
this::operator()
{
import system.cstdio;
puts("Hello, world!");
}
Dream Maker
mob
Login()
..()
world << "Hello, world!"
Dylan
module: hello
format-out("Hello, world!\n");
Ed and Ex (Ed extended)
a hello world! . p
Eiffel
class HELLO_WORLD
creation
make
feature
make is
local
io:BASIC_IO
do
create io
io.put_string("%N Hello, world!")
end -- make
end -- class HELLO_WORLD
English
Display "Hello, world" at the top left corner of the screen.
Erlang
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("Hello, world!\n").
Euphoria
puts(1, "Hello, world!")
F#
print_endline "Hello, world!"
Factor
"Hello, world!" print
filePro
@once: mesgbox "Hello, world!" ; exit
Fjoelnir
"hello" < main
{
main ->
stef(;)
stofn
skrifastreng(;"Hallo, veroeld!"),
stofnlok
}
*
"GRUNNUR"
;
FOCAL
type "Hello, world!",!
or
t "Hello, world!",!
Focus
-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('Hello, world!');
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;
Forth
: HELLO ( -- ) ." Hello, world!" CR ; HELLO \ or instead of compiling a new routine, one can type directly in the Forth interpreter console CR ." Hello, world!" CR
FORTRAN
PROGRAM HELLO
PRINT *, 'Hello, world!'
END
Fril
?((pp "Hello, world!"))
Frink
println["Hello, world!"]
Gambas
See also GUI section.
PUBLIC SUB Main() Print "Hello, world!" END
GEMBase 4GL
procedure_form hello
begin_block world
print "Hello, world!"
end_block
end_form
Groovy
println "Hello, world"
Game Maker
In the draw event of some object:
draw_text(x,y,"Hello, world!")
Or to show a splash screen message:
show_message("Hello, world!")
Or in the messages window in debug mode:
show_debug_message("Hello, world!")
Haskell
main = putStrLn "Hello, world!"
Heron
program HelloWorld;
functions {
_main() {
print_string("Hello, world!");
}
}
end
HP 33s
(Handheld Hewlett-Packard RPN-based scientific calculator.)
LBL H SF 10 EQN RCL H RCL E RCL L RCL L RCL O R/S RCL W RCL O RCL R RCL L RDL D ENTER R/S
HP-41 & HP-42S
(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)
01 LBLTHELLO
02 THELLO, WORLD
03 PROMPT
HyperTalk (Apple HyperCard's scripting programming language)
put "Hello, world!"
or
Answer "Hello, world!"
IDL
print,"Hello, world!"
Inform
[ Main; "Hello, world!"; ];
Io
"Hello, world!" print
or
write("Hello, world!\n")
Iptscrae
ON ENTER {
"Hello, " "world!" & SAY
}
J
Simplest:
Hello, world!
Probably closest in semantics:
'Hello, world!'
Jal
include 16f877_20 include hd447804
hd44780_clear
hd44780 = "H" hd44780 = "e" hd44780 = "l" hd44780 = "l" hd44780 = "o" hd44780 = " " hd44780 = "W" hd44780 = "o" hd44780 = "r" hd44780 = "l" hd44780 = "d" hd44780 = "!"
Java
See also GUI section.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Java byte-code
(disassembler output of javap -c HelloWorld)
public class HelloWorld extends java.lang.Object{
public HelloWorld();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3; //String Hello, world!
5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
JavaScript
JavaScript does not have native (built in) input or output routines. Instead it relies on the facilities provided by it's host environment.
Using a standard Web browser's document object
document.writeln('Hello, world!');
or with an alert, using a standard Web browser's window object (window.alert)
alert('Hello, world!');
or, from the Mozilla command line implementation
print('Hello, world!');
JSP
<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<HTML>
<BODY>
<% out.println(" Hello World"); %> !
</BODY>
</HTML>
K
`0:"Hello, world!\n"
Kogut
WriteLine "Hello, world!"
KPL (Kids Programming Language)
Program HelloWorld
Method Main()
ShowConsole()
ConsoleWriteLine("Hello World")
End Method
End Program
Lasso
Output: 'Hello, world!';
or
Output('Hello, world!');
or simply
'Hello, world!';
Limbo
implement Command;
include "sys.m"
sys: Sys;
include "draw.m";
include "sh.m";
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
sys->print("Hello World!\n");
}
Lisp
Lisp has many dialects that have appeared over its almost fifty-year history.
Common Lisp
(format t "Hello, world!~%")
or
(write-line "Hello, world!")
or merely:
"Hello, world!"
Scheme
(display "Hello, world!")
Emacs Lisp
(print "Hello, world!")
AutoLisp
(print "Hello, world!")
XLISP
(print "Hello, world!")
Logo
print [Hello, world!]
or
pr [Hello, world!]
In mswlogo only
messagebox [Hi] [Hello, world!]
Lua
print "Hello, world!"
or
io.write("Hello, world!\n")
LuaPSP
screen:print(1,1,"Hello, world!") screen:flip()
M (MUMPS)
W "Hello, world!"
M# Fictional Computer Language
Script
main(std:string >>arg<< / OS.GetArg)
{
std:stream >>CONSOLE<< / OS.Console;
CONSOLE:Write([byte]{0048, 0065, 006C, 006C, 006F, 002C, 0058, 006F, 0072, 006C, 0064});
// H e l l o , W o r l d //
}
Command WI
# # DEFINE g >>CONSOLE<< / OS.Console
# % proc CONSOLE:Write([byte]{0048, 0065, 006C, 006C, 006F, 002C, 0058, 006F, 0072, 006C, 0064})
Command WoI
# @ Write([byte]{0048, 0065, 006C, 006C, 006F, 002C, 0058, 006F, 0072, 006C, 0064})
M4
Hello, world!
Macsyma, Maxima
print("Hello, world!")$
Malbolge
(=<`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk**
hKs_dG5[m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W10/.R,+O<
Maple
print("Hello, world!");
Mathematica
Print["Hello, world!"]
or simply:
"Hello, world!"
MATLAB
disp('Hello, world!')
Maude
fmod HELLOWORLD is protecting STRING . op helloworld : -> String . eq helloworld = "Hello, world!" . endfm red helloworld .
Max
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;
mIRC Script
//echo Hello, world!
Model 204
BEGIN PRINT 'Hello, world!' END
Modula-2
MODULE Hello;
FROM InOut IMPORT WriteLn, WriteString;
BEGIN
WriteString ("Hello, world!");
WriteLn
END Hello.
MOO
notify(player, "Hello, world!");
MS-DOS batch
(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.). It's very common for batchfiles to start with two lines of "@echo off" and "cls".
@echo Hello, world!
For MS-DOS 3.0 or lower
echo off cls echo Hello, world!
MUF
: main me @ "Hello, world!" notify ;
Natural
WRITE "Hello, world!" END
Nemerle
The easiest way to get Nemerle print "Hello, world!" would be that:
System.Console.WriteLine("Hello, world!");
however, in bigger applications the following code would be probably more useful:
using System.Console;
module HelloWorld
{
Main():void
{
WriteLine("Hello, world!");
}
}
Oberon
Oberon is both the name of a programming language and an operating system.
Program written for the Oberon operating system:
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.
Freestanding Oberon program using the standard Oakwood library:
MODULE Hello;
IMPORT Out;
BEGIN
Out.String("Hello, world!");
Out.Ln
END Hello.
Objective C
Functional C Version
#import <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
Object-Oriented C Version
#import <stdio.h>
#import <objc/Object.h>
@interface Hello : Object
{
}
- hello;
@end
@implementation Hello
- hello
{
printf("Hello, world!\n");
}
@end
int main(void)
{
id obj;
obj = [Hello new];
[obj hello];
[obj free];
return 0;
}
OPENSTEP/Cocoa Version
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSLog(@"Hello, world!");
return 0;
}
OCaml
print_endline "Hello, world!"
occam
#USE "course.lib"
PROC hello.world(CHAN OF BYTE screen!)
out.string("Hello, world!*n", 0, screen!)
:
or without using course.lib
PROC hello.world(CHAN OF BYTE screen!)
SEQ
screen ! 'H'
screen ! 'e'
screen ! 'l'
screen ! 'l'
screen ! 'o'
screen ! ','
screen ! ' '
screen ! 'w'
screen ! 'o'
screen ! 'r'
screen ! 'l'
screen ! 'd'
screen ! '!'
screen ! '*n'
:
OPL
See also GUI section.
PROC hello: PRINT "Hello, world" ENDP
OPS5
(object-class request
^action)
(startup
(strategy MEA)
(make request ^action hello)
)
(rule hello
(request ^action hello)
(write |Hello, world!| (crlf))
)
OPS83
module hello (main)
{ procedure main( )
{
write() |Hello, world!|, '\n';
};
};
Oz programming language
{Show 'Hello World'}
Parrot assembly language
print "Hello, world!\n" end
Pascal
program hello;
begin writeln('Hello, world!'); end.
Perl
print "Hello, world!\n";
or
package Hello;
sub new() { bless {} }
sub Hello() { print "Hello, World! \n" }
package main;
my $hello = new Hello;
$hello->Hello();
(This is the first example in Learning Perl; the semicolon is optional.) There's More Than One Way To Do It ;-)
Perl 6
"Hello, world!".say
PHP
<?php echo "Hello, world!"; ?>
or
<?php print "Hello, world!"; ?>
or if short open tags are enabled
<?="Hello, world!"?>
Pike
int main() {
write("Hello, world!\n");
return 0;
}
PILOT
T:Hello, world!
PL/SQL
-- start anonymous block
set serveroutput on size 10000000;
begin
dbms_output.enable(1000000);
dbms_output.put_line('Hello, world!');
end;
-- end anonymous block
PL/I
Test: proc options(main);
put list('Hello, world!');
end Test;
POP-11
'Hello, world' =>
PostScript
See PDL section
Processing
println("Hello, world!");
Progress 4GL
message "Hello, world!" view-as alert-box.
Prolog
:- write('Hello, world'),nl.
Pure Data
#N canvas 0 0 300 300 10; #X obj 100 100 loadbang; #X msg 100 150 hello world; #X obj 100 200 print; #X connect 0 0 1 0; #X connect 1 0 2 0;
Python
print "Hello, world!"
or, for interactive prompt,
"Hello, world!"
or
import sys
sys.stdout.write("Hello, world!\n")
or
__import__("sys").stdout.write('Hello, world!\n')
Rebol
See also GUI section.
print "Hello, world!"
Redcode
; Should work with any MARS >= ICWS-86
; with 128x64 gfx core
Start MOV 0,2455
MOV 0,2458
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2460
MOV 0,2465
MOV 0,2471
MOV 0,2471
MOV 0,2471
MOV 0,2479
MOV 0,2482
MOV 0,2484
MOV 0,2484
MOV 0,2484
MOV 0,2486
MOV 0,2486
MOV 0,2486
MOV 0,2486
MOV 0,2488
MOV 0,2493
MOV 0,2493
MOV 0,2493
MOV 0,2493
MOV 0,2497
MOV 0,2556
MOV 0,2559
MOV 0,2560
MOV 0,2565
MOV 0,2570
MOV 0,2575
MOV 0,2578
MOV 0,2585
MOV 0,2588
MOV 0,2589
MOV 0,2592
MOV 0,2593
MOV 0,2596
MOV 0,2597
MOV 0,2603
MOV 0,2605
MOV 0,2608
MOV 0,2667
MOV 0,2670
MOV 0,2671
MOV 0,2676
MOV 0,2681
MOV 0,2686
MOV 0,2689
MOV 0,2696
MOV 0,2699
MOV 0,2700
MOV 0,2703
MOV 0,2704
MOV 0,2707
MOV 0,2708
MOV 0,2714
MOV 0,2716
MOV 0,2719
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2779
MOV 0,2779
MOV 0,2779
MOV 0,2782
MOV 0,2787
MOV 0,2792
MOV 0,2795
MOV 0,2802
MOV 0,2805
MOV 0,2806
MOV 0,2809
MOV 0,2810
MOV 0,2810
MOV 0,2810
MOV 0,2810
MOV 0,2812
MOV 0,2818
MOV 0,2820
MOV 0,2823
MOV 0,2882
MOV 0,2885
MOV 0,2886
MOV 0,2891
MOV 0,2896
MOV 0,2901
MOV 0,2904
MOV 0,2911
MOV 0,2912
MOV 0,2913
MOV 0,2914
MOV 0,2917
MOV 0,2918
MOV 0,2919
MOV 0,2922
MOV 0,2928
MOV 0,2930
MOV 0,2933
MOV 0,2992
MOV 0,2995
MOV 0,2996
MOV 0,3001
MOV 0,3006
MOV 0,3011
MOV 0,3014
MOV 0,3021
MOV 0,3022
MOV 0,3023
MOV 0,3024
MOV 0,3027
MOV 0,3028
MOV 0,3030
MOV 0,3032
MOV 0,3038
MOV 0,3040
MOV 0,3103
MOV 0,3106
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3111
MOV 0,3111
MOV 0,3111
MOV 0,3120
MOV 0,3121
MOV 0,3124
MOV 0,3124
MOV 0,3124
MOV 0,3126
MOV 0,3129
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3131
MOV 0,3131
MOV 0,3131
MOV 0,3131
MOV 0,3135
JMP 0
REFAL
$ENTRY GO{=<Prout 'Hello, world!'>;}
REXX, ARexx, NetRexx, and Object REXX
/* */ say "Hello, world!"
RPG
Free-Form Syntax
/FREE
DSPLY 'Hello, world!';
*InLR = *On;
/END-FREE
Traditional Syntax
With this syntax, a constant has to be used because the message must be placed in positions 12 to 25, between apostrophes.
d TestMessage c Const( 'Hello, world!' )
c TestMessage DSPLY
c EVAL *InLR = *On
RPG Code
Message Window
Using the internal message window, a simple hello world program can be rendered thus:
mwin("Hello, world!")
wait()
On Screen Text
An additional way to render text is by using the built in text() function.
text(1,1,"Hello, world!") wait()
RPL
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 >>
RT Assembler
_name Hello~World!
pause Hello~World!
exit
_end
Ruby
See also GUI section.
puts "Hello, world!"
or
"Hello, world!".each { |s| puts s }
SAS
data _null_; put 'Hello, world!'; run;
Sather
class HELLO_WORLD is main is #OUT+"Hello, world\n"; end; end;
Scala
object HelloWorld with Application {
Console.println("Hello, world!");
}
sed
(note: requires at least one line of input)
sed -ne '1s/.*/Hello, world!/p'
Seed7
$ include "seed7_05.s7i";
const proc: main is func
begin
writeln("Hello, world!");
end func;
Self
'Hello, world!' print.
Simula
BEGIN
OutText("Hello, world!");
OutImage;
END
Smalltalk
Transcript show: 'Hello, world!'; cr
SML
print "Hello, world!\n";
SNOBOL
OUTPUT = "Hello, world!"
END
Span
class Hello {
static public main: args {
Console << "Hello, world!\n";
}
}
SPARK
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;
SPITBOL
OUTPUT = "Hello, world!"
END
SPSS Syntax
ECHO "Hello, world!".
SQL
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');
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!").
SuperCollider
"Hello World".postln;
TACL
#OUTPUT Hello, world!
Tcl (Tool command language)
See also GUI section.
puts "Hello, world!"
TOM (rewriting language)
public class HelloWorld {
%include { string.tom }
public final static void main(String[] args) {
String who = "world";
%match(String who) {
"World" -> { System.out.println("Hello, " + who + "!"); }
_ -> { System.out.println("Don't panic"); }
}
}
Turing
put "Hello, world!"
TSQL
Declare @Output varchar(16) Set @Output='Hello, world!' Select @Output
or, simpler variations:
Select 'Hello, world!' Print 'Hello, world!'
UNIX-style shell
echo 'Hello, world!'
or using an inline 'here document'
cat <<'DELIM' Hello, world! DELIM
or
printf '%s' $'Hello, world!\n'
or for a curses interface:
dialog --msgbox 'Hello, world!' 0 0
Verilog
module main();
initial begin
#0 $display("Hello world!");
#1 $finish;
end
endmodule
or (a little more complicated)
module hello(clk);
input clk;
always @(posedge clk) $display("Hello world!");
endmodule
module main();
reg clk;
hello H1(clk);
initial begin
#0 clk=0;
#5 clk=1;
#1 $finish;
end
endmodule
module hello(clk);
input clk;
always @(posedge clk) $display("Hello world!");
endmodule
module main();
reg clk;
hello H1(clk);
initial begin
#0 clk=0;
#23 $display("--23--");
#100 $finish;
end
always #5 clk=~clk;
endmodule
VHDL
use std.textio.all;
entity Hello is
end Hello;
architecture Hello_Arch of Hello is
begin
p : process
variable l:line;
begin
write(l, String'("Hello, world!"));
writeline(output, l);
wait;
end process;
end Hello_Arch;
Visual Basic Script
WScript.Echo "Hello, world!"
[See additional examples on this same page under "In VBScript only": [[2]]
Visual Prolog
#include @"pfc\console\console.ph"
goal
console::init(),
stdio::write("Hello, world!").
Windows PowerShell
"Hello, world!"
or:
Write-Host "Hello, world!"
or:
echo "Hello, world!"
or:
[System.Console]::WriteLine("Hello, world!")
Yorick
write, "Hello, world!";
Note: The semicolon is optional.
Graphical user interfaces (GUIs)
ActionScript (Macromedia flash mx)
this.createTextField("hello_txt",0,10,10,100,20);
this.hello_txt.text="Hello, world!";
AppleScript
See also TUI section.
display dialog "Hello, world!" buttons {"OK"} default button 1
Or to have the OS synthesize it and literally speak out the words "hello world!" (with no comma, as that would cause the synthesizer to pause)
say "Hello world!"
boo
See also TUI section.
import System.Drawing
import System.Windows.Forms
f = Form()
f.Controls.Add(Label(Text: "Hello, world!", Location: Point(40,30)))
f.Controls.Add(Button(Text: "Ok", Location: Point(50, 55), Click: {Application.Exit()}))
Application.Run(f)
Functional equivalent of C# program below.
C#
See also TUI section.
using System; using System.Drawing; using System.Windows.Forms;
public class HelloWorldForm : Form
{
public static void Main()
{
Application.Run(new HelloWorldForm());
}
public HelloWorldForm()
{
Label label = new Label();
label.Text = "Hello, world!";
label.Location = new Point(40,30);
this.Controls.Add(label);
Button button = new Button();
button.Text = "OK";
button.Location = new Point(50,55);
this.Controls.Add(button);
button.Click += new EventHandler(button_Click);
}
private void button_Click(Object sender, EventArgs e)
{
Application.Exit();
}
}
- or simply
public class HelloWorld
{
static void Main()
{
System.Windows.Forms.MessageBox.Show("Hello, world!");
}
}
Cocoa or GNUStep (In Objective C)
#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
Curl
{curl 3.0, 4.0 applet}
{curl-file-attributes character-encoding = "utf-8"}
Hello, world!
Delphi, Kylix
program Hello_World;
uses
QDialogs;
begin
ShowMessage('Hello, world!');
end.
Euphoria
MS-Windows only - basic.
include msgbox.e
if message_box("Hello, world!", "Hello", 0) then end if
MS-Windows only - using Win32Lib library
include win32lib.ew
createForm({
";Window; Hello",
";Label; Hello, world!"
})
include w32start.ew
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();
}
G (LabVIEW)
See Labview.
Gambas
See also TUI section.
PUBLIC SUB Main()
Message.Info("Hello, world!")
END
GTK+ (in C++ using GTKmm)
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
HelloWorld helloworld;
Gtk::Main::run(helloworld); //Shows the window and returns when it is closed.
return 0;
}
#include <gtkmm/button.h>
#include <gtkmm/window.h>
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
virtual void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
#include <iostream>
HelloWorld::HelloWorld()
: m_button("Hello, world!") // creates a new button with the specified text as the label
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method. The on_button_clicked() method is defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
add(m_button);
// The final step is to display this newly created widget...
m_button.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked()
{
std::cout << "Hello, world!" << std::endl;
}
GTK+ (in Python using PyGTK)
import pygtk
pygtk.require("2.0")
import gtk
# create window
window = gtk.Window(WINDOW_TOPLEVEL)
window.set_title("Hello, world!")
window.connect("destroy", gtk.main_quit)
# create vertical box
vbox = gtk.VBox()
# create label
lbl = Label("Hello, world!")
# add label to vertical box
vbox.add(lbl)
# create button
button = gtk.Button("OK")
# when this button is clicked, exit.
button.connect("clicked", main_quit)
# add buton to vertical box
vbox.add(button)
# add vertical box to window
window.add(vbox)
# show it all
window.show_all()
# enter the GTK mainloop.
gtk.main()
or
import gtk gtk.MessageDialog(message_format="Hello, world!").run()
Gtk# (in C#)
using Gtk;
using GtkSharp;
using System;
class Hello {
static void Main()
{
Application.Init ();
Window window = new Window("");
window.DeleteEvent += cls_evn;
Button close = new Button ("Hello, world!");
close.Clicked += new EventHandler(cls_evn);
window.Add(close);
window.ShowAll();
Application.Run ();
}
static void cls_evn(object obj, EventArgs args)
{
Application.Quit();
}
}
GTK+ 2.x (in Euphoria)
include gtk2/wrapper.e Info(NULL,"Hello","Hello, world!")
IOC/OCL (in IBM VisualAge for C++)
#include <iframe.hpp>
void main()
{
IFrameWindow frame("Hello, world!");
frame.showModally()
}
Java
See also TUI section.
import javax.swing.JOptionPane;
public class Hello
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "Hello, world!");
}
}
Java applet
- 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 and JScript
- 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 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 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 are many other ways:
javascript:document.write('Hello, world!\n');
K
This creates a window labeled "Hello, world!" with a button labeled "Hello, world!".
hello:hello..l:"Hello, world!" hello..c:`button `show$`hello
LabVIEW (G)
See LabVIEW.
Linden Scripting Language (LSL)
This says "Hello, world!" on the public chat channel:
default {
state_entry() {
llSay(0, "Hello, world!");
}
}
This sets red floating text of "Hello, world!" above the prim where the script is held:
default {
state_entry() {
llSetText("Hello, world!", <1,0,0>, 1.0);
}
}
MeshDot
This actually plots Hi
draw(r 1 1 ) draw(r 1 2 ) draw(r 1 3 ) draw(r 1 4 ) draw(r 1 5 ) draw(r 1 6 ) draw(r 1 7 ) draw(r 1 8 ) draw(r 1 9 ) draw(r 2 5 ) draw(r 3 5 ) draw(r 4 5 ) draw(r 5 5 ) draw(r 6 1 ) draw(r 6 2 ) draw(r 6 3 ) draw(r 6 4 ) draw(r 6 5 ) draw(r 6 6 ) draw(r 6 7 ) draw(r 6 8 ) draw(r 6 9 ) draw(g 8 4 ) draw(g 8 6 ) draw(g 8 7 ) draw(g 8 8 ) draw(g 8 9 )
Microsoft Foundation Classes (in C++)
#include <afx.h>
#include <afxwin.h>
class CHelloWin : public CWnd
{
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnPaint(void)
{
CPaintDC dc(this);
dc.TextOut(15, 3, TEXT("Hello, world!"), 13);
}
};
BEGIN_MESSAGE_MAP(CHelloWin, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
class CHelloApp : public CWinApp
{
virtual BOOL InitInstance();
};
CHelloApp theApp;
LPCTSTR wndClass;
BOOL CHelloApp::InitInstance()
{
CWinApp::InitInstance();
CHelloWin* hello = new CHelloWin();
m_pMainWnd = hello;
wndClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, 0, (HBRUSH)::GetStockObject(WHITE_BRUSH), 0);
hello->CreateEx(0, wndClass, TEXT("Hello MFC"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 120, 50, NULL, NULL);
hello->ShowWindow(SW_SHOW);
hello->UpdateWindow();
return TRUE;
}
Adobe Flex MXML
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Label text="Hello, world!"/> </mx:Application>
NSIS
This creates a message box saying "Hello, world!".
OutFile "HelloWorld.exe"
Name "Hello World"
Caption "Hello World"
Section Hello World
SectionEnd
Function .onInit
MessageBox MB_OK "Hello, world!"
Quit
FunctionEnd
OPL
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
Pure Data
- patch as ASCII-art
[hello world( | [print]
- patch as sourcecode
#N canvas 0 0 300 300 10; #X msg 100 150 hello world; #X obj 100 200 print; #X connect 0 0 1 0;
Qt toolkit (in C++)
#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();
}
or
#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(window);
QPushButton *hello = new QPushButton("Hello, world!", window);
//connect the button to quitting
hello->connect(hello, SIGNAL(clicked()), &app, SLOT(quit()));
layout->addWidget(hello);
layout->setMargin(10);
layout->setSpacing(10);
window->show();
return app.exec();
}
REALbasic
MsgBox "Hello, world!"
Rebol
See also TUI section.
view layout [text "Hello, world!"]
Or for different looks, just use different styles :
view layout [
h1 "Hello, world!"
vh1 "Hello, world!"
h2 "Hello, world!"
vh2 "Hello, world!"
h3 "Hello, world!"
vh3 "Hello, world!"
vtext "Hello, world!"
; or personalize it, if you want:
vtext "Hello, world!" red italic underline font-size 16
]
As a notify window, it's even simpler :
notify "Hello, world!"
RPL
See also TUI section.
(On Hewlett-Packard HP-48G and HP-49G series calculators.)
<< "Hello, world!" MSGBOX >>
RTML
Hello () TEXT "Hello, world!"
Ruby with WxWidgets
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
Ruby with GTK+
See also TUI section.
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("delete_event") { Gtk.main_quit; false }
button = Gtk::Button.new("Hello, world!")
button.signal_connect("clicked") { Gtk.main_quit; false }
window.add(button)
window.show_all
Gtk.main
Ruby with Tk
See also TUI section
require 'tk'
window = TkRoot.new { title 'Hello, world!' }
button = TkButton.new(window) {
text 'Hello, world!'
command proc { exit }
pack
}
Tk.mainloop
Smalltalk
See also TUI section.
Evaluate in a workspace
Dialog confirm: 'Hello, world!'
Using the Morphic GUI toolkit of Squeak Smalltalk:
('Hello, World!' asMorph openInWindow) submorphs second color: Color black
Using wxSqueak:
Wx messageBox: 'Hello, world!'
SWT (in Java)
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 ();
}
}
Tcl/Tk
See also TUI section.
label .l -text "Hello, world!" pack .l
Python with Tkinter
See also TUI section.
import Tkinter r = Tkinter.Tk() w = Tkinter.Label(r, text="Hello, world!") w.pack() r.mainloop()
or, more primitively:
import tkMessageBox as mb mb.showinfo(message="Hello, world!")
Ubercode
Ubercode 1 class Hello
public function main()
code
call Msgbox("Hello", "Hello, world!")
end function
end class
Uniface
message "Hello World"
Virtools
Visual Basic including VBA
Sub Main()
MsgBox "Hello, world!"
End Sub
Visual Basic .NET 2003
Private Sub frmForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("Hello, world!", "HELLO, WORLD!")
Me.Close()
End Sub
Note that the previous example will only work when the code is entered as part of a Form subclass, such as the one created by default when generating a new project in the Visual Studio programming environment. Equivalently, the following code is roughly equivalent to the traditional Visual Basic code:
Public Class MyApplication
Shared Sub Main()
MessageBox.Show("Hello, world!", "HELLO WORLD")
End Sub
End Class
Visual Prolog (note box)
#include @"pfc\vpi\vpi.ph"
goal
vpiCommonDialogs::note("Hello, world!").
Windows API (in C)
This uses the Windows API to create a full window containing the text. Another example below uses the built-in MessageBox function instead.
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "MainWnd";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wincl;
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;
}
Windows PowerShell
[System.Windows.Forms.MessageBox]::Show("Hello, world!")
Windows Script Host with VBScript
<job id="HelloWorld">
<script language="VBScript">
WScript.Echo "Hello, world!"
</script>
</job>
In VBScript only
'CScript output stream to the command line or WScript GUI driven output WScript.Echo "Hello, world!"
'WSH 5.6 allows for standard in and standard out at the command line
WScript.StdOut.Write("Hello, world!")
'GUI driven output with control options for the display icon and window title Msgbox "Hello, world!",vbInformation,"Hello, world example"
'GUI driven output with all of the previous features including display time in seconds
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Popup "Hello, world!",3,"Hello, world example",vbInformation
Set WSHShell = Nothing
Windows Script Host with JScript
<job id="HelloWorld">
<script language="JScript">
WScript.Echo( "Hello, world!" ) ;
</script>
</job>
XAML/WPF
<Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005"> <TextBlock>Hello, world!</TextBlock> </Page>
XSL(T)
There are many ways to do this in XSL, the simplest being:
<xsl:template match="/"> <xsl:text>Hello, world!</xsl:text> </xsl:template>
If the output is to be HTML, it would be:
<xsl:template match="/">
<html>
<body>
<h1>Hello, world!</h1>
</body>
</html>
</xsl:template>
XUL
Type the following in a text file (e.g. hello.world.xul) and then open with Mozilla Firefox or another Gecko-based browser.
<?xml-stylesheet type="text/css" ?> <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" align="center" pack="center" flex="1"> <description>Hello, world!</description> </window>
ZK
Server-centric XUL-based Web framework. By use of Ajax, it enables browsers like IE capable of processing XUL. You can view the "hello world" window directly here.
<window title="1st window" border="normal" width="200px"> Hello, world! </window>
Esoteric programming languages
See: Hello world program in esoteric languages
Document formats
ASCII
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
Page description languages
XHTML 1.1
(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">
<head>
<title>Hello, world!</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
HTML
(simple)
<html> <body> Hello, world! </body> </html>
<html> and <body>-tags are not necessary for informal testing. or simply write it as text without tags.
Hello, world!
HTML 4.01 Strict (full)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Hello, world!</title> </head> <body> <p>Hello, world!</p> </body> </html>
The first paragraph of the W3C Recommendation on The global structure of an HTML document also features this example.
%PDF-1.0 1 0 obj << /Type /Catalog /Pages 3 0 R /Outlines 2 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Count 1 /Kids [4 0 R] >> endobj 4 0 obj << /Type /Page /Parent 3 0 R /Resources << /Font << /F1 7 0 R >>/ProcSet 6 0 R >> /MediaBox [0 0 612 792] /Contents 5 0 R >> endobj 5 0 obj << /Length 44 >> stream BT /F1 24 Tf 100 100 Td (Hello World) Tj ET endstream endobj 6 0 obj [/PDF /Text] endobj 7 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /MacRomanEncoding >> endobj xref 0 8 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000179 00000 n 0000000322 00000 n 0000000415 00000 n 0000000445 00000 n trailer << /Size 8 /Root 1 0 R >> startxref 553 %%EOF
PostScript
% Displays on console. (Hello, world!) =
%! % Displays as page output. /Courier findfont 24 scalefont setfont 100 100 moveto (Hello, world!) show showpage
RTF
{\rtf1\ansi\deff0
{\fonttbl {\f0 Courier New;}}
\f0\fs20 Hello, world!
}
TeX
Hello world \bye
LaTeX 2ε
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
Media-based scripting languages
AviSynth
BlankClip()
Subtitle("Hello, world!")
(Creates a video with default properties)
Lingo (Macromedia Director scripting language)
on exitFrame me put "Hello, world!" end
Outputs the string to the message window if placed in a single movie frame. Alternatively, to display an alert box stating the message you could use
on exitFrame me alert "Hello, world!" end
POV-Ray
#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 }
}
See also
External links
- ACM "Hello World" project
- "HelloWorld online on Web, and steps beyond HelloWorld"
- A Collection of Hello World Programs
- Another Collection of Hello World Programs with 260+ programs, including "Hello World" in several human languages















