Hallo-Welt-Programm

Programm, das „Hallo Welt“ ausgibt
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 17. Februar 2004 um 00:20 Uhr durch Levin (Diskussion | Beiträge) (HTML-Code verändert, so dass er nicht als solcher interpretiert wird). Sie kann sich erheblich von der aktuellen Version unterscheiden.

Hallo, Welt! oder auch "Hello World!" (engl.), ist ein bekanntes Beispielprogramm, das am Anfang fast jedes 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.

Line-oriented (aka Console)

   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
   BEGIN { print "Hallo, Welt!" }
   Traditionelles, unstrukturiertes BASIC
   10 PRINT "Hallo, Welt!"
   20 END
   Eher modernes, strukturiertes BASIC
   print "Hallo, Welt!"
   GET "LIBHDR"
   LET START () BE
   $(
       WRITES ("Hallo, Welt!*N")
   $)
   print("Hallo, Welt!");
   #include <stdio.h>
   int main(void) {
       printf("Hallo, Welt!\n");
       return 0;
   }
   #include <iostream>
   int main() {
       std::cout << "Hallo, Welt!\n";
   }
   class HalloWeltApp {
    public static void Main() {
       System.Console.WriteLine("Hallo, Welt!");
    }
   }
   IDENTIFICATION DIVISION.
   PROGRAM-ID.     HALLO-WELT.
   ENVIRONMENT DIVISION.
   DATA DIVISION.
   PROCEDURE DIVISION.
   DISPLAY "Hallo, Welt!".
   STOP RUN.
   (format t "Hallo Welt!~%")
   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
       -module(Hallo).
       -export([Hallo_Welt/0]).
       Hallo_Welt() -> io:fwrite("Hallo, Welt!\n").
   ." Hallo, Welt!" CR
      PROGRAM HALLO
      WRITE(*,10)
   10 FORMAT('Hallo, Welt!')
      STOP
      END
   "Hallo, Welt" print
   ON ENTER {
       "Hallo, " "Welt!" & SAY
   }
   public class Hallo {
       public static void main(String[] args) {
           System.out.println("Hallo, Welt!");
       }
   }
   print "Hallo, Welt!"
    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!
   let main () =
      print_endline "Hallo Welt!";;
   PROC Hallo:
     PRINT "Hallo, Welt"
   ENDP
   program Hallo;
   begin
       writeln('Hallo, Welt!');
   end.
   print "Hallo, Welt!\n";
   <?php
       print("Hallo, Welt!");
   ?>
   #!/usr/local/bin/pike
   int main() {
       write("Hallo, Welt!\n");
       return 0;
   }
   Test: procedure options(main);
      declare My_String char(20) varying initialize('Hallo, Welt!');
      put skip list(My_String);
   end Test;
   ?- write("Hallo, Welt!"), nl.
   print "Hallo, Welt!"
   say "Hallo, Welt!"
   print "Hallo, Welt!\n"
   (display "Hallo, Welt!")
   (newline)

Benötigt mindestens eine Zeile als Eingabe:

   sed -ne '1s/.*/Hallo, Welt!/p'
   Transcript show: 'Hallo, Welt!'
   print "Hallo, Welt!\n";
       OUTPUT = "Hallo, Welt!"
   END
   select "Hallo, Welt!" as message;
   sub main
   print "Hallo, Welt"
   end sub
   puts "Hallo, Welt!"
   :Disp "Hallo, Welt!"
   put "Hallo, Welt!"
   echo 'Hallo, Welt!'


Graphical User Interfaces - as traditional applications

   MsgBox "Hallo, Welt!"
   PUBLIC SUB Form_Enter()
   PRINT "Hallo Welt"
   END

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;
   }
   #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;
   }
   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 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!')
   <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <box align="center">
   <label value="Hallo, Welt!" />
   </box>
   </window>


Exotische Programmiersprachen (auch esoterisch genannt)

   30,14,16,101,16,108,16,32,16,111,16,108,1,12,16,72,16,108,16,111,16,87,16,114,16,100,16,33

See [1] for a Hallo, Welt program in 4DL.

   \/>>>>>>\+\<<<\+!\>>\+\<<<<\-\<\-!\>>>\+\<<<\-!!+++!\/\-\/>>>>>\+\<<\+\<\+!---!\>>>
   \+\>\+\<<<\-\<<<\-!\>>>\-!\<<\+\<\+!\>\-\>\-!\>\-!\/\-/>>>>>\+\<<<<<\+!\/\-\/>>>\+\<<\+!

Note: this actually prints "HI" instead of "Hallo, Welt".

   84 > 84 > 84 > 84 > 84 > 84 > 84 > 85
                                      \/
   85 < 86 < 86 < 86 < 86 < 86 < 0E < 66
   \/                       /\
   84 > 84 > 0C > 8C > E5 > 0F   84 > 85
                       \/        /\   \/
   85 < 86 < 86 < 3E < 0E   84 > 83 < 86
   \/                       /\   \/
   84 > 84 > 84 > 84 > 84 > 0F   84 > 85
                                      \/
   00 < 00 < 00 < B6 < 0E < B6 < 0E < 86


Note: this actually prints "Hi" instead of "Hallo, Welt".

   Baa, badassed areas!
   Jarheads' arses
         queasy nude adverbs!
       Dare address abase adder? *bares baser dadas* HA!
   Equalize, add bezique, bra emblaze.
     He (quezal), aeons liable.  Label lilac "bulla," ocean sauce!
   Ends, addends,
      duodena sounded amends.
"!dlrow olleH">v
               ,
              ^_@
   main: "Hallo, Welt!\n">out :
   ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<
   +++++++++++++++.>.+++.------.--------.>+.>.
   Ingredients.
   72 g haricot beans
   101 eggs
   108 g lard
   111 cups oil
   32 zucchinis
   119 ml water
   114 g red salmon
   100 g dijon mustard
   33 potatoes
   Method.
   Put potatoes into the mixing bowl. Put dijon mustard into the mixing bowl. Put lard into the mixing
   bowl. Put red salmon into the mixing bowl. Put oil into the mixing bowl. Put water into the mixing
   bowl. Put zucchinis into the mixing bowl. Put oil into the mixing bowl. Put lard into the mixing
   bowl. Put lard into the mixing bowl. Put eggs into the mixing bowl. Put haricot beans into the
   mixing bowl. Liquefy contents of the mixing bowl. Pour contents of the mixing bowl into the
   baking dish.
   Serves 1.
   AGb-A#A#+A+%A#DF-AC#
   when a=0 then put "Hallo, Welt!" set a=1
   Universe of bear hatchery says Hallo. Welt!.
    It   powers     the marshy things;
   the power of the snowmelt overrides.
   H
   PLEASE DO ,1 <- #13
   DO ,1 SUB #1 <- #238
   DO ,1 SUB #2 <- #112
   DO ,1 SUB #3 <- #112
   DO ,1 SUB #4 <- #0
   DO ,1 SUB #5 <- #64
   DO ,1 SUB #6 <- #238
   DO ,1 SUB #7 <- #26
   DO ,1 SUB #8 <- #248
   DO ,1 SUB #9 <- #168
   DO ,1 SUB #10 <- #24
   DO ,1 SUB #11 <- #16
   DO ,1 SUB #12 <- #158
   DO ,1 SUB #13 <- #52
   PLEASE READ OUT ,1
   PLEASE GIVE UP
   (=<`:9876Z4321UT.-Q+*)M'&%$H"!~}|Bzy?=|{z]KwZY44Eq0/{mlk**hKs_dG5
   [m_BA{?-Y;;Vb'rR5431M}/.zHGwEDCBA@98\6543W10/.R,+O<
   "HALLO, WELT.!"
   $$
   #0<a>0:0#0>e>0:0#0>f>0>0:0#0^f>0:0#0+4>0:0#0#h>0:0#0^f>0:0#0<g>0:0#0>f
   >0:0#0<e>0:0#0?4>0:0#0^1>0:0#0>1>0:0^0
   Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook.
   Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook?
   Ook! Ook! Ook? Ook! Ook? Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook.
   Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook? Ook. Ook. Ook.
   Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook. Ook? Ook! Ook! Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
   Ook? Ook. Ook? Ook. Ook? Ook. Ook? Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook.
   Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
   Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook!
   Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook. 
   d / ("Hallo, Welt!")
   0   'd' 'l' 'r' 'o' 'w' ' ' ',' 'o' 'l' 'l' 'e' 'h' s   0   c   0   ret
   Hallo Welt
      forget
      come from "Hallo" print "Hallo, " return
      come from "Welt" print "Welt !" return

Please see [2] for a Hallo, Welt program in Piet.

Note that this is not a complete "Hallo, Welt!" program.

   - - - ..- ...-.---.;newline
   - - - .-. - ..-.- ...-. ---.;!
   - - - ...- . . -.---.;d
   ----. . . -.---.;l
   ----. . -...---.;r
   ----. -...---.;o
   ----...-.- ..-. ---.;W


     0a21646c726f77202c6f6c6c6548
   , :::::::::::::::::::::::::::: ,
    )
    ==============================
   F
                                  O F
                                  c
                                  =
   sidefxio
   void main
        print 'H
        print 'e
        print 'l
        print 'l
        print 'o
        print ',
        print as char 32
        print 'w
        print 'o
        print 'r
        print 'l
        print 'd
        print '!
              G                                  GGG
   >++++++++++>!+++++++!++++++++++!+++!+##!!!!##-G+G
   G.+++++++++++++++##!!##.++!.+++..+++++++.+!.++! G
   G!.+++.------.--------.!+.!.G                  GG
   [ `Hallo, _32 `Welt! _13 _10 ] \15 outs \0 halt
   ; Hallo, Welt in SMITH - version 2 (loop)
   ; R0 -> index into string (starts at R10)
   ; R2 -> -1
     MOV R0, 10
     MOV R2, 0
     SUB R2, 1
     MOV R[R0], "Hallo, Welt!"
     MOV TTY, R[R0]
     SUB R0, R2
     MOV R1, R0
     SUB R1, 23
     NOT R1
     NOT R1
     MUL R1, 8
     COR +1, -7, R1
   :V+++++;:XVV;:v-----;:xvv;XXXXXXX++.<XXXXXXXXXX+.V
   ++..+++.<XXX++.>>XV.XX++++.+++.v-.x++.<XXX+++.<X.>
   In the House
   You are inside the small blue house on Pine St. The floor is carpeted and the walls are
   paneled in a light coloured wood. The door is to the north.
   Julie is here.
   >JULIE, Hallo, Welt!
   Julie doesn't respond.
   >X JULIE
   Julie is a twentysomething woman with short brunette hair.
   >QUIT
   `
   ``si`k``s.H``s.e``s.l``s.l``s.o``s. 
   ``s.w``s.o``s.r``s.l``s.d``s.!``sri
   ``si``si``si``si``si``si``si``si`ki

Note: actually prints "What do you want, universe?" in Klingon.

   ~ nuqneH { ~ 'u' ~ nuqneH disp disp } name
   nuqneH
   Functions:
   || No functions for this program !!
   Stuff:
           1/Hallo is chrs!
           1/Sz, 1/Total are all cplx!
   Text:
   || Initialize the data !!
           Hallo < "Hallo, Welt!"!
           Size Hallo > Sz!
           Total < 0!
   || Take the string length and multiply by 100 !!
           - Size - 0 Total > Total %10000!
   || Print and delete a character that many times !!
           &       WELT < FCHRS (Hallo)!
           &       Hallo < - Hallo FCHRS (Hallo)!
           &&      %Total!
   || Add a newline !!
           WELT < nl!
   :Endtext
   1 print("Hallo Welt!");

Please see [3] for a Hallo, Welt program in Whitespace.

   <print>Hallo Welt</print>


Textauszeichnungssprachen

Die folgenden Sprachen sind keine Programmiersprachen, sondern Textauszeichnungssprachen, also Sprachen, mit denen man einen im Computer gespeicherten Text für die Ausgabe auf dem Bildschirm oder mit dem Drucker formatieren kann. Analog zum "Hallo Welt!"-Programm ist ein "Hallo Welt!"-Dokument in einer dieser Sprachen ein Beispieldokument, das nur den Text "Hallo Welt" enhält.

   Hallo, Welt!

oder in hexadezimaler Schreibweise:

   48 61 6C 6C 6F 2C 20 57 65 6C 74 21
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
   <html>
     <head>
       <title>Hallo, Welt!</title>
       <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
     </head>
     <body>
       <p>
         Hallo, Welt!
       </p>
     </body>
   </html>
   /font /Courier findfont 24 scalefont
   font setfont
   100 100 moveto
   (Hallo Welt!) show
   showpage
   \font\HW=cmr10 scaled 3000
   \leftline{\HW Hallo Welt}
   \bye