Hello world program examples

From Wikipedia, the free encyclopedia
Jump to: navigation, search

The Hello world program is a simple computer program that prints (or displays) the string "Hello World". It is typically one of the simplest programs possible in almost all computer languages, and often used as first program to demonstrate a programming language. As such it can be used to quickly compare syntax differences between various programming languages. The following is a list of canonical hello world programs in many programming languages.


Contents

[edit] Languages

[edit] A

[edit] ActionScript 3.0

trace ("Hello World!");

or (if you want it to show on the stage)

package com.example
{
    import flash.text.TextField;
    import flash.display.Sprite;
 
    public class Greeter extends Sprite
    {
        public function Greeter()
        {
            var txtHello:TextField = new TextField();
            txtHello.text = "Hello World";
            addChild(txtHello);
        }
    }
}

[edit] ADA

with Ada.Text_Io;
 
procedure Hello_World is
begin
    Ada.Text_Io.Put_Line("Hello World!");
end;

[edit] ALGOL

BEGIN
   DISPLAY ("Hello World!");
END.

[edit] Algol 68

print("Hello world!")

[edit] Amiga E

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

[edit] APL

⎕←'Hello world!'

[edit] Assembly Language - x86 DOS

; The output file is 22 bytes.
; 14 bytes are taken by "Hello, world!$
;
; Written by Stewart Moss - May 2006
; This is a .COM file so the CS and DS are in the same segment
;
; I assembled and linked using TASM
;
; tasm /m3 /zn /q hello.asm
; tlink /t hello.obj
 
.model tiny
.code
org 100h
 
main  proc
 
      mov    ah,9                       ; Display String Service
      mov    dx,offset hello_message    ; Offset of message (Segment DS is the right segment in .COM files)
      int    21h                        ; call DOS int 21h service to display message at ptr ds:dx
 
      retn                              ; returns to address 0000 off the stack 
                                        ; which points to bytes which make int 20h (exit program)
 
hello_message db 'Hello, World!$'
 
main  endp
end   main

[edit] Assembly Language - x86 Windows 32 bit

; This program displays "Hello, World!" in a windows messagebox and then quits.
;
; Written by Stewart Moss - May 2006
;
; Assemble using TASM 5.0 and TLINK32  
;      
; The ouput EXE is standard 4096 bytes long. 
; It is possible to produce really small windows PE exe files, but that
; is outside of the scope of this demo.
 
         .486p
         .model  flat,STDCALL
include  win32.inc
 
extrn            MessageBoxA:PROC
extrn            ExitProcess:PROC
 
 
.data
 
 
HelloWorld db "Hello, World!",0
msgTitle db "Hello world program",0
 
.code
Start:
         push    MB_ICONQUESTION + MB_APPLMODAL + MB_OK
         push    offset msgTitle
         push    offset HelloWorld
         push    0
         call    MessageBoxA
 
         push 0
         call ExitProcess
ends
end Start

[edit] AWK

BEGIN { print "Hello world!" }

[edit] B

[edit] BASIC

PRINT "Hello world!"

[edit] Batch File

@ECHO off
ECHO Hello World!
PAUSE
@ECHO on

[edit] brainfuck

+++++ +++++             initialize counter (cell #0) to 10
[                       use loop to set the next four cells to 70/100/30/10
    > +++++ ++              add  7 to cell #1
    > +++++ +++++           add 10 to cell #2 
    > +++                   add  3 to cell #3
    > +                     add  1 to cell #4
    <<<< -                  decrement counter (cell #0)
]                   
> ++ .                  print 'H'
> + .                   print 'e'
+++++ ++ .              print 'l'
.                       print 'l'
+++ .                   print 'o'
> ++ .                  print ' '
<< +++++ +++++ +++++ .  print 'W'
> .                     print 'o'
+++ .                   print 'r'
----- - .               print 'l'
----- --- .             print 'd'
> + .                   print '!'
> .                     print '\n'

[edit] C

[edit] C

#include <stdio.h>
 
int main(void)
{
  printf("Hello world\n");
  return 0;
}

[edit] C++

#include <iostream>
 
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

[edit] C#

using System;
class ExampleClass
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, world!");
    }
}

[edit] CFML (ColdFusion)

CF Script:

<cfscript>
    variables.greeting = "Hello, world!";
    WriteOutput( variables.greeting );
</cfscript>

CFML Tags:

<cfset variables.greeting = "Hello, world!">
<cfoutput>#variables.greeting#</cfoutput>

[edit] Clojure

Console version:

(println "Hello, world!")

GUI version:

(javax.swing.JOptionPane/showMessageDialog nil "Hello, world!")

[edit] COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO-WORLD.
       PROCEDURE DIVISION.
           DISPLAY 'Hello, world'.
           STOP RUN.

[edit] D

[edit] D

import std.stdio;
 
void main()
{
  writeln("Hello World!");
}

[edit] Dart

main()
{
  print('Hello World!');
}

[edit] Delphi

{$APPTYPE CONSOLE}
begin
  Writeln('Hello, world!');
end.


[edit] F

[edit] F#

printfn "Hello World!"

[edit] Fortran

program hello
   print *, "Hello World"
end program hello

[edit] G

[edit] Game Maker Language

str='Hello World'
 
//Using the show_message() function:
show_message(str);
 
//Using the draw_text() function:
draw_text(320,240,str);

[edit] Go

package main
 
import "fmt"
 
func main() {
   fmt.Println("Hello World!")
}

[edit] Groovy

println "Hello World!"

[edit] H

[edit] Haskell

main = print "Hello World!"

[edit] I

[edit] Io

 "Hello world!" println

[edit] J

[edit] Java

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

[edit] JavaScript

document.write('Hello world!');

or

alert('Hello world!');

or (when using Node.js)

console.log('Hello world!');


[edit] L

[edit] Lisp

(print "Hello world!")

[edit] Lua

print("Hello World!")

[edit] M

[edit] Mathematica

Print["Hello World!"]

[edit] mIRC Script

echo -a Hello World!

[edit] O

[edit] ObjectiveC

#import <stdio.h>
 
int main(void)
{
    printf("Hello, World!\n");
    return 0;
}

[edit] OCaml

 print_endline "Hello world!"

[edit] Opa

A "hello world" web server:

server = Server.one_page_server("Hello", ( -> <>Hello world!</>))

[edit] P

[edit] Pascal

program HelloWorld;
 
begin
  WriteLn('Hello world!');
end.

[edit] Perl 5

use v5.10;
say 'Hello World.';

[edit] PHP

<?php
echo "Hello, world";
?>

[edit] PL/SQL

SET SERVEROUTPUT ON;
BEGIN
    DBMS_OUTPUT.PUT_LINE('Hello world!');
END;
/

[edit] PowerShell

Write-Host "Hello world!"

[edit] Prolog

main :- write('Hello world!'), nl.

[edit] Python 2

print 'Hello World'

[edit] Python 3

print("Hello World")

[edit] R

[edit] R

cat('Hello world!')

[edit] Racket

Trivial "hello world" program:

#lang racket
"Hello, World!"

Running this program produces "Hello, World!". More direct version:

#lang racket
(printf "Hello, World!\n")

A "hello world" web server using Racket's web-server/insta language:

 
#lang web-server/insta
(define (start request) (response/xexpr '(html (body "Hello World"))))}

[edit] RPL

<< "Hello World!" MSGBOX >>

[edit] RTL/2

TITLE Hello World;

LET NL=10;

EXT PROC(REF ARRAY BYTE) TWRT;

ENT PROC INT RRJOB();
    TWRT("Hello World!#NL#");
    RETURN(1);
ENDPROC;

[edit] Ruby

puts "Hello world!"

[edit] S

[edit] Scala

object HelloWorld extends Application {
  println("Hello world!")
}

[edit] Scheme

(display "Hello World")

[edit] Shell

echo Hello World

[edit] Simula

Begin
   OutText ("Hello World!");
   Outimage;
End;

[edit] Smalltalk

Transcript show: 'Hello, world!'.

[edit] SNOBOL

ID: HelloWorld
Code:
     write.HelloWorld
End

[edit] SQL

SELECT 'Hello world!' FROM DUAL -- DUAL is a standard table in Oracle.
SELECT 'Hello world!' -- This will work in SQL Server.

[edit] T

[edit] Tcl

puts "Hello, World!"

[edit] TI-Basic

Disp "HELLO WORLD!"

[edit] V

[edit] Visual Basic

 MsgBox "Hello, world!"

[edit] Visual Basic .NET

Module Module1
    Sub Main() 
        Console.WriteLine("Hello, world!")
    End Sub
End Module
 
'non-console example:
Class Form1
    Public Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load()
        MsgBox("Hello, world!")
    End Sub
End Class
::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::