Hallo Welt     Zurück                            (aus Wikipedia, der freien Enzyklopädie )


Hallo, Welt! oder auch "Hello World!" (engl.), ist ein bekanntes Beispielprogramm, das am Anfang fast jeden Programmierkurses vorkommt.

Das fertige Computerprogramm gibt lediglich den Text "Hello world!" (oder etwas ähnliches) auf dem Bildschirm aus. Dieses Programm soll dem angehenden Programmierer zeigen, was alles für ein vollständiges Programm (in der betreffenen Programmiersprache) benötigt wird, und einen ersten Einblick in die Syntax geben.

Inhaltsverzeichnis

1 Line-oriented (aka Console)

1.1 Ada
1.2 Assembler (x86 CPU, DOS, TASM syntax)
1.3 AWK
1.4 BASIC
1.5 BCPL
1.6 C
1.7 C++
1.8 C#
1.9 COBOL
1.10 Common LISP
1.11 Eiffel
1.12 Erlang
1.13 Forth
1.14 Fortran
1.15 Iptscrae
1.16 Java
1.17 Lua
1.18 MIXAL
1.19 MS-DOS batch
1.20 OCaml
1.21 OPL
1.22 Pascal
1.23 Perl
1.24 PHP
1.25 Pike
1.26 PL/I
1.27 Prolog
1.28 Python
1.29 REXX
1.30 Ruby
1.31 Scheme
1.32 sed
1.33 Smalltalk
1.34 SML
1.35 SNOBOL
1.36 SQL
1.37 StarOffice Basic
1.38 Tcl
1.39 TI-BASIC
1.40 Turing
1.41 Unix-Shell

2 Graphical User Interfaces - as traditional applications

2.1 Visual Basic
2.2 C++ bindings for GTK graphics toolkit
2.3 Windows API (in C)
2.4 Java

3 Graphical User Interfaces - Webbrowser basiert

3.1 Java applet
3.2 JavaScript, aka ECMAScript
3.3 XUL

5 Sonstiges

5.1 HTML
5.2 PostScript
5.3 TeX
5.4 ASCII

Line-oriented (aka Console)

Ada

    with Ada.Text_Io; use Ada.Text_Io;
    procedure Hallo is
    begin
       Put_Line ("Hallo, Welt!");
    end Hallo;

Assembler (x86 CPU, DOS, TASM syntax)

    MODEL SMALL
    IDEAL
    STACK 100H
    DATASEG
        HW      DB      'Hallo, Welt!$'
    CODESEG
        MOV AX, @data
        MOV DS, AX
        MOV DX, OFFSET HW
        MOV AH, 09H
        INT 21H
        MOV AX, 4C00H
        INT 21H
    END

AWK

    BEGIN { print "Hallo, Welt!" }

BASIC

    Traditionelles, unstrukturiertes BASIC
    10 PRINT "Hallo, Welt!"
    20 END
    Eher modernes, strukturiertes BASIC
    print "Hallo, Welt!"

BCPL

    GET "LIBHDR"
    LET START () BE
    $(
        WRITES ("Hallo, Welt!*N")
    $)

C

    #include <stdio.h>
    int main(void) {
        printf("Hallo, Welt!\n");
        return 0;
    }

C++

    #include <iostream>
    using namespace std;
    int main() {
        cout << "Hallo, Welt!" << endl;
        return 0;
    }

C#

    class HalloWeltApp {
     public static void Main() {
        System.Console.WriteLine("Hallo, Welt!");
     }
    }

COBOL

    IDENTIFICATION DIVISION.
    PROGRAM-ID.     HALLO-WELT.
    ENVIRONMENT DIVISION.
    DATA DIVISION.
    PROCEDURE DIVISION.
    DISPLAY "Hallo, Welt!".
    STOP RUN.

Common LISP

    (format t "Hallo Welt!~%")

Eiffel

    class HALLO_WELT
    creation
        make
    feature
        make is
        local
                io:BASIC_IO
        do
                !!io
                io.put_string("%N Hallo, Welt!")
        end -- make
    end -- class HALLO_WELT

Erlang

        -module(Hallo).
        -export([Hallo_Welt/0]).
        Hallo_Welt() -> io:fwrite("Hallo, Welt!\n").

Forth

    ." Hallo, Welt!" CR

Fortran

       PROGRAM HALLO
       WRITE(*,10)
    10 FORMAT('Hallo, Welt!')
       STOP
       END

Iptscrae

    ON ENTER {
        "Hallo, " "Welt!" & SAY
    }

Java

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

Lua

    print "Hallo, Welt!"

MIXAL

     TERM    EQU    19          the MIX console device number
             ORIG   1000        start address
     START   OUT    MSG(TERM)   output data at address MSG
             HLT                halt execution
     MSG     ALF    "MIXAL"
             ALF    " HELL"
             ALF    "O WOR"
             ALF    "LD   "
             END    START       end of the program

MS-DOS batch

    @echo off
    echo Hallo, Welt!

OCaml

    let main () =
       print_endline "Hallo Welt!";;

OPL

    PROC Hallo:
      PRINT "Hallo, Welt"
    ENDP

Pascal

    program Hallo;
    begin
        writeln('Hallo, Welt!');
    end.

Perl

    print "Hallo, Welt!\n";

PHP

    <?php
        print("Hallo, Welt!");
    ?>

Pike

    #!/usr/local/bin/pike
    int main() {
        write("Hallo, Welt!\n");
        return 0;
    }

PL/I

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

Prolog

    ?- write("Hallo, Welt!"), nl.

Python

    print "Hallo, Welt!"

REXX

    say "Hallo, Welt!"

Ruby

    print "Hallo, Welt!\n"

Scheme

    (display "Hallo, Welt!")
    (newline)

sed

Benötigt mindestens eine Zeile als Eingabe:

    sed -ne '1s/.*/Hallo, Welt!/p'

Smalltalk

    Transcript show: 'Hallo, Welt!'

SML

    print "Hallo, Welt!\n";

SNOBOL

        OUTPUT = "Hallo, Welt!"
    END

SQL

    select "Hallo, Welt!" as message;

StarOffice Basic

    sub main
    print "Hallo, Welt"
    end sub

Tcl

    puts "Hallo, Welt!"

TI-BASIC

    :Disp "Hallo, Welt!"

Turing

    put "Hallo, Welt!"

Unix-Shell

    echo 'Hallo, Welt!'

Graphical User Interfaces - as traditional applications

Visual Basic

    MsgBox "Hallo, Welt!"

C++ bindings for GTK graphics toolkit

    #include <iostream>
    #include <gtkmm/main.h>
    #include <gtkmm/button.h>
    #include <gtkmm/window.h>
    using namespace std;
    class HalloWelt : public Gtk::Window {
    public:
      HalloWelt();
      virtual ~HalloWelt();
    protected:
      Gtk::Button m_button;
      virtual void on_button_clicked();
    };
    HalloWelt::HalloWelt()
    : m_button("Hallo, Welt!") {
        set_border_width(10);
        m_button.signal_clicked().connect(SigC::slot(*this,
                                          &HalloWelt::on_button_clicked));
        add(m_button);
        m_button.show();
    }
    HalloWelt::~HalloWelt() {}
    void HalloWelt::on_button_clicked() {
        cout << "Hallo, Welt!" << endl;
    }
    int main (int argc, char *argv[]) {
        Gtk::Main kit(argc, argv);
        HalloWelt HalloWelt;
        Gtk::Main::run(HalloWelt);
        return 0;
    }

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, "Hallo, Welt!", 13);
            EndPaint(hwnd, &ps);
            break;
      case WM_DESTROY:
            PostQuitMessage(0);
            break;
      default:
            return DefWindowProc(hwnd, message, wParam, lParam);
      }
      return 0;
    }

Java

    import java.awt.*;
    import java.awt.event.*;
    public class HalloFrame extends Frame {
      HalloFrame(String title) {
        super(title);
      }
      public void paint(Graphics g) {
        super.paint(g);
        java.awt.Insets ins = this.getInsets();
        g.drawString("Hallo, Welt!", ins.left + 25, ins.top + 25);
      }
      public static void main(String args [])
      {
        HalloFrame fr = new HalloFrame("Hallo");
        fr.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e)
            {
              System.exit( 0 );
            }
          }
        );
        fr.setResizable(true);
        fr.setSize(500, 100);
        fr.setVisible(true);
      }
    }

Graphical User Interfaces - Webbrowser basiert

Java applet

Java applets funktionieren in Verbindung mit HTML.

    <HTML>
    <HEAD>
    <TITLE>Hallo Welt</TITLE>
    </HEAD>
    <BODY>
    HalloWelt Program says:
    <APPLET CODE="HalloWelt.class" WIDTH=600 HEIGHT=100>
    </APPLET>
    </BODY>
    </HTML>
    import java.applet.*;
    import java.awt.*;
    public class HalloWelt extends Applet {
      public void paint(Graphics g) {
        g.drawString("Hallo, Welt!", 100, 50);
      }
    }

JavaScript, aka ECMAScript

JavaScript ist ein Skriptsprache, die insbesondere in HTML-Dateien verwendet wird. Der nachfolgende Kode kann in HTML-Quelltext eingebaut werden:

    <script language="javascript">
    function HalloWelt()
    {
        javascript: alert("Hallo, Welt!");
    }
    </script>
    <a href="javascript:this.location()"
     onclick="javascript:HalloWelt();">Hallo Welt 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('Hallo, Welt!')">Hallo Welt 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('Hallo, Welt!')

XUL

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

Sonstiges

HTML

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
    <HTML>
    <HEAD>
    <TITLE>Hallo, Welt!</TITLE>
    </HEAD>
    <BODY>
    Hallo, Welt!
    </BODY>
    </HTML>

PostScript

    /font /Courier findfont 24 scalefont
    font setfont
    100 100 moveto
    (Hallo Welt!) show
    showpage

TeX

    \font\HW=cmr10 scaled 3000
    \leftline{\HW Hallo Welt}
    \bye

ASCII

    Hallo, Welt!

oder in hexadezimaler Schreibweise:

    48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21

Von "http://de.wikipedia.org/wiki/Hallo_Welt"
Diese Seite wurde zuletzt geändert um 17:14, 19. Dez 2003. Diese Seite ist unter der GNU FDL verfügbar.