Hello world program

From Wikipedia, the free encyclopedia.

A "hello world" program is a computer program that simply 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 simpler programs possible in a computer language. Some are surprisingly complex, especially in some graphical user interface (GUI) contexts. Some others are surprisingly simple, 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 LCD display (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. The example program from that book prints "hello, world" (i.e., no capital letters, no exclamation sign; those have entered the tradition later). However, the first known instance of the usage of "Hello world!" is in A Tutorial Introduction to the Language B, by Brian Kernighan. [1] (http://cm.bell-labs.com/cm/cs/who/dmr/bintro.html)

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" in the way of actual calculation, is usually exhibited.

Here are some examples in different languages:

Contents [hide]

1.1 ABC
1.2 Ada
1.3 AmigaE
1.4 APL
1.5 Assembly language

1.6 AWK
1.7 BASIC

1.8 BCPL
1.9 BLISS
1.10 C
1.11 C#
1.12 C++
1.13 CIL
1.14 Clean
1.15 CLIST
1.16 COBOL
1.17 Common Lisp
1.18 D
1.19 DCL batch
1.20 Ed and Ex (Ed extended)
1.21 Eiffel
1.22 Erlang
1.23 EUPHORIA
1.24 F#
1.25 Focus
1.26 Forte TOOL
1.27 Forth
1.28 FORTRAN
1.29 Frink
1.30 Gambas
1.31 Game Maker
1.32 Haskell
1.33 Heron
1.34 HP-41 & HP-42S
1.35 IDL
1.36 Inform
1.37 Io
1.38 Iptscrae
1.39 Java
1.40 JVM
1.41 Kogut
1.42 Logo
1.43 Lua
1.44 M (MUMPS)
1.45 Mathematica
1.46 Modula-2
1.47 MS-DOS batch
1.48 MUF
1.49 Objective C
1.50 OCaml
1.51 OPL
1.52 OPS5
1.53 Pascal
1.54 Perl
1.55 PHP
1.56 Pike
1.57 PL/I
1.58 POP-11
1.59 POV-Ray
1.60 Prolog
1.61 Python
1.62 REXX, NetRexx, and Object REXX
1.63 RPL
1.64 Ruby
1.65 SAS
1.66 Sather
1.67 Scala
1.68 Scheme
1.69 sed
1.70 Self
1.71 Smalltalk
1.72 SML
1.73 SNOBOL
1.74 SQL
1.75 STARLET
1.76 TACL
1.77 Tcl
1.78 Turing
1.79 TSQL
1.80 UNIX-style shell

Text user interface (TUI) (aka console, line-oriented)


ABC

    WRITE "Hello World"

Ada

    with Ada.Text_Io;
    procedure Hello is
    begin
       Ada.Text_Io.Put_Line ("Hello, world!");
    end Hello;

AmigaE

    PROC main()
       WriteF('Hello, World!')
    ENDPROC

APL

    'Hello World'

Assembly language

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
            LDA    MSG,X    ; load initial char
    @LP:    JSR    $FFD2    ; chrout
            INX
            LDA    MSG,X
            BNE    @LP
            RTS

Accumulator/Index microcoded machine: Data General Nova, RDOS

See the example section of the Nova article.

Expanded accumulator machine: Intel x86, MS-DOS, TASM

    MODEL   SMALL
    IDEAL
    STACK   100H
  
    DATASEG
            MSG DB 'Hello, world!$'
  
    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

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-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

AWK

    BEGIN { print "Hello, world!" }

BASIC

MS BASIC (traditional, unstructured)

    10 PRINT "Hello, world!"
    20 END

TI-BASIC

On TI-80-TI-86 calculators.

    :Disp "Hello, world!"

On TI-89/TI-92 calculators.

    :HelloWorld()
    :Prgm
    :Disp "Hello, world!"
    :EndPrgm

StarOffice/OpenOffice Basic

    sub main
        print "Hello, World"
    end sub

Structured BASIC

    print "Hello, world!"
    end

BCPL

    GET "LIBHDR"
  
    LET START () BE
    $(
        WRITES ("Hello, world!*N")
    $)

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

C

    #include <stdio.h>

    int main()
    {
        printf("Hello, world!\n");
        return 0;
    }

C#

    using System;

    class HelloWorldApp {
        public static void Main() {
            Console.WriteLine("Hello, world!");
        }
    }

C++

    #include <iostream>

    int main()
    {
        std::cout << "Hello, world!\n";
    }

CIL

    .method public static void Main() cil managed
    {
         .entrypoint
         .maxstack 8
         ldstr "Hello world."
         call void [mscorlib]System.Console::WriteLine(string)
         ret
    }

Clean

    module hello
  
    Start :: String
    Start = "Hello, world"

CLIST

    PROC 0
    WRITE Hello, World!

COBOL

    IDENTIFICATION DIVISION.
    PROGRAM-ID.     HELLO-WORLD.
  
    ENVIRONMENT DIVISION.
  
    DATA DIVISION.
  
    PROCEDURE DIVISION.
    DISPLAY "Hello, world!".
    STOP RUN.

Common Lisp

    (format t "Hello world!~%")

D

    int main() {
        printf("Hello, world!\n");
        return 0;
    }

DCL batch

    $ write sys$output "Hello, world!"

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

Eiffel

    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

Erlang

        -module(hello).
        -export([hello_world/0]).
  
        hello_world() -> io:fwrite("Hello, world!\n").

EUPHORIA

    puts(1, "Hello, world!")

F#

    type data =
        { first: string;
          second: string; }
  
        let myData =
            { first="Hello";
              second="world"; }
  
        let _ =
            print_string myData.first;
            print_string " ";
            print_string myData.second;
            print_newline()

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('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;

Forth

    ." Hello, world!" CR

FORTRAN

       PROGRAM HELLO
       WRITE(*,10)
    10 FORMAT('Hello, world!')
       STOP
       END

Frink

    println["Hello, world!"]

Gambas

See also GUI section.

    PUBLIC SUB Main()
      Print "Hello, world!"
    END

Game Maker

In the draw event of some object:

    draw_text(x,y,"Hello World");

Haskell

    module HelloWorld (main) where
  
    main = putStr "Hello World\n"

Heron

  program HelloWorld;
  functions {
    _main() {
      String("Hello, world!") |> GetStdOut();
    }
  }
  end

HP-41 & HP-42S

(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)

  
    01 LBLTHELLO
    02 THELLO, WORLD
    03 PROMPT

HP-41 output

IDL

    print,"Hello world!"

Inform

    [ Main;
      print "Hello, world!^";
    ];

Io

    "Hello world!" print

or

    write("Hello world!\n")

Iptscrae

    ON ENTER {
        "Hello, " "World!" & SAY
    }

Java

See also GUI section.

    public class Hello {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
        }
    }

JVM

(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

Kogut

    WriteLine "Hello, world!"

Logo

    print [hello  world!]

or

    pr [Hello World!]

In mswlogo only

    messagebox [Hi] [Hello World]

Lua

    print "Hello, world!"

M (MUMPS)

    W "Hello, world!"

Mathematica

 Print["Hello World"]

Modula-2

    MODULE Hello;
  
    FROM Terminal2 IMPORT WriteLn; WriteString;
  
    BEGIN
       WriteString("Hello, world!");
       WriteLn;
    END Hello;

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 5.0.)

    @echo Hello, world!

MUF

    : main
      me @ "Hello, world!" notify
    ;
    

Objective C

   #import <Foundation/Foundation.h>
  
      int main (int argc, const char * argv[]) {
       NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  
       NSLog(@"Hello, World!");
       [pool release];
       return 0;
   }

OCaml

    let _ =
       print_endline "Hello world!";;

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))
    )

Pascal

    program Hello (output);
    begin
        writeln('Hello, world!');
    end.

Perl

    print "Hello, world!\n";

PHP

    echo "Hello, world!";

Pike

    int main() {
        write("Hello, world!\n");
        return 0;
    }

PL/I

    Test: procedure options(main);
       declare My_String char(20) varying initialize('Hello, world!');
       put skip list(My_String);
    end Test;

POP-11

    'Hello world' =>

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 }
  }

Prolog

    write('Hello world'),nl.

Python

    print "Hello, world!"

REXX, NetRexx, and Object REXX

   say "Hello, world!"

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
    >>

Ruby

See also GUI section.

    puts "Hello, world!"

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!");
    }

Scheme

    (display "Hello, world!")
    (newline)

sed

(note: requires at least one line of input)

    sed -ne '1s/.*/Hello, world!/p'

Self

    'Hello, World!' print.

Smalltalk

    Transcript show: 'Hello, world!'

SML

    print "Hello, world!\n";

SNOBOL

        OUTPUT = "Hello, world!"
    END

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 (e.g. MySQL dialect)

    select 'Hello, world';

Or, more simply

    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

    puts "Hello, world!"

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!'

Graphical user interfaces (GUIs)


ActionScript (Macromedia flash mx)

    trace ("hello, world")

AppleScript

    display dialog "Hello, world!"

Or to have the OS synthesize it and literally say "hello world!"

   say "Hello world!" -- comma left out because that would cause the synthesizer to pause and sound silly

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

Delphi,Kylix

    ShowMessage("Hello, world!");

Gambas

See also TUI section.

    PUBLIC SUB Main()
      Message.Info("Hello, world!")
    END

Image:gambashelloworld.png

GTK toolkit (in C++)

    #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;
    }

GTK# (in C#)

using Gtk;
using GtkSharp;
using System;

class Hello {

        static void Main()
        {
                Application.Init ();

                Window window = new Window ("helloworld");
                window.Show();

                Application.Run ();

        }
}

GTK 2.x (in Euphoria)

    include gtk2/wrapper.e
  
    Info(NULL,"Hello","Hello World!")

Image:EuphoriaHelloWorld.png

Java

See also TUI section.

    import javax.swing.JOptionPane;
  
    public class Hello {
        public static void main(String[] args) {
            JOptionPane.showMessageDialog(null, "Hello, world!");
            System.exit(0);
        }
    }

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 (aka ECMAScript) and JScript

JavaScript 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()">Hello World Example</a>
An easier method uses JavaScript implicitly, calling the reserved alert function. Cut and paste the following line inside the <BODY> .... </BODY> HTML tags.
     <a href="#" onclick="alert('Hello, world!')">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!')

Image:js-hello_world.png

OPL

See also TUI section.

(On Psion Series 3 and later compatible PDAs.)

    PROC guihello:
      ALERT("Hello, world!","","Exit")
    ENDP

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();
    }

REALbasic

    MsgBox "Hello, world!"

RPL

See also TUI section.

(On Hewlett-Packard HP-48G and HP-49G series calculators.)

    << "Hello, World!" MSGBOX >>

SWT

import org.eclipse.swt.widgets.*;

public class Main {
        public static void main (String [] args) {
               Display display = new Display ();
               Shell shell = new Shell(display);
               shell.open ();
               while (!shell.isDisposed ()) {
                     if (!display.readAndDispatch ()) display.sleep ();
               }
               display.dispose ();
        }
}

Visual Basic incl VBA

    MsgBox "Hello, world!"

Windows API (in C)

    #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))
      {
            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 easy :

    #include <windows.h>
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        MessageBox(NULL, "Hello World", "", MB_OK);
        return 0;
    }

Windows Script Host

    WScript.Echo "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

XUL

    <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <box align="center">
    <label value="Hello, world!" />
    </box>
    </window>

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

HTML 4.01 Strict

(Using UTF-8 character set.)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Hello, world!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>

XHTML 1.1

(Using UTF-8 character set.)

Please note that this document must also be sent with the appropriate HTTP Header, most preferably "application/xhtml+xml", but it MAY also be sent as "application/xml" or "text/xml"; however it MUST NOT be sent as "text/html"; see XHTML Media Types (http://www.w3.org/TR/xhtml-media-types/#application-xhtml-xml) for further info.

<?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>

RTF

    {\rtf1\ansi\deff0
    {\fonttbl {\f0 Courier New;}}
    \f0\fs20 Hello, world!
    }

Page description languages

PostScript

    /Courier findfont 24 scalefont setfont
    100 100 moveto
    (Hello world!) show
    showpage
In executing the interpreter, one can simply write
 (Hello world!) stack

TeX

    Hello world
    \bye

See also

External links