|
List of Hello world program examples
The Hello world program is a simple computer program that prints (or displays) the string "Hello, world!" or some variant thereof. 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 91 programming languages. A ABAPREPORT HELLOWORLD.WRITE 'Hello, world!'. ActionScript 3.0Main article: ActionScriptor (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); } }} Adawith Ada.Text_IO; procedure Hello_World is use Ada.Text_IO;begin Put_Line("Hello, world!");end; Adventure Game Studio ScriptDisplay("Hello, world!"); or (if you want to draw it to the background surface) DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();surface.DrawString(0, 100, Game.NormalFont, "Hello, world!");surface.Release(); ALGOLBEGIN DISPLAY ("Hello, world!");END. ALGOL 68 Amiga EPROC main() WriteF('Hello, world!')ENDPROC APL⎕←'Hello, world!' Assembly Language — MOS Technology 6502, CBM KERNEL
A_CR = $0D ;carriage return BSOUT = $FFD2 ;kernel ROM sub, write to current output device ; LDX #$00 ;starting index in .X register ; LOOP LDA MSG,X ;read message text BEQ LOOPEND ;end of text ; JSR BSOUT ;output char INX BNE LOOP ;repeat ; LOOPEND RTS ;return from subroutine ; MSG .BYT 'Hello, world!',A_CR,$00 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.codeorg 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 endpend main 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 output 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,STDCALLinclude win32.inc extrn MessageBoxA:PROCextrn ExitProcess:PROC .data HelloWorld db "Hello, world!",0msgTitle db "Hello world program",0 .codeStart: push MB_ICONQUESTION + MB_APPLMODAL + MB_OK push offset msgTitle push offset HelloWorld push 0 call MessageBoxA push 0 call ExitProcessendsend Start Assembly language – x86-64 Linux, AT&T syntax .section .rodatastring: .ascii "Hello, world!\n\0"length: .quad . -string #Dot = 'here' .section .text .globl _start #Make entry point visible to linker_start: movq $4, %rax #4=write movq $1, %rbx #1=stdout movq $string, %rcx movq length, %rdx int $0x80 #Call Operating System movq %rax, %rbx #Make program return syscall exit status movq $1, %rax #1=exit int $0x80 #Call System Again Assembly language – Z80 EQU CR = #0D ; carriage return EQU PROUT = #xxxx ; character output routine ; LD HL,MSG ; Point to message ; PRLOOP LD A,(HL) ; read byte from message AND A ; set zero flag from byte read RET Z ; end of text if zero JSR PROUT ; output char INC HL ; point to next char JR PRLOOP ; repeat ; MSG DB "Hello, world!",CR,00 ; AutoHotkey AutoItMsgbox(64, "", "Hello, world!") AWKBEGIN { print "Hello, world!" } B BASIC Batch File BCPLGET "LIBHDR"LET START() BE$( WRITES("Hello, world!*N")$) 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' C C#include <stdio.h> int main(int argc, char *argv[]){ printf("Hello, world!\n"); return 0;} C++#include <iostream> int main(){ std::cout << "Hello, World!" << std::endl;} C#using System;class Program{ public static void Main() { Console.WriteLine("Hello, world!"); Console.ReadKey(true); }} Casio BASICMain article: Casio BASIC COMAL-80 Common Intermediate Language.assembly Hello {}.assembly extern mscorlib {}.method static void Main(){ .entrypoint .maxstack 1 ldstr "Hello, world!" call void [mscorlib]System.Console::WriteLine(string) call string[mscorlib]System.Console::ReadKey(true) pop ret} ColdFusion Markup Language (CFML)CF Script: <cfscript> variables.greeting = "Hello, world!"; WriteOutput( variables.greeting );</cfscript> CFML Tags: <cfset variables.greeting = "Hello, world!"><cfoutput>#variables.greeting#</cfoutput> ClojureConsole version: (println "Hello, world!") GUI version: (javax.swing.JOptionPane/showMessageDialog nil "Hello, world!") COBOL IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. PROCEDURE DIVISION. DISPLAY 'Hello, world!'. STOP RUN. D Dimport std.stdio; void main(){ writeln("Hello, world!");} Dartmain(){ print('Hello, world!');} DCLWRITE SYS$OUTPUT "Hello, world!" Delphi{$APPTYPE CONSOLE}begin Writeln('Hello, world!');end. E Erlangio:format("~s~n", ["Hello, world!"]) F F# Falcon printl( "Hello, world!" ) or Forth Fortran(Fortran 95 and later) program hello write (*,*) 'Hello, world!'end program hello (Fortran 90 ) program hello print *, 'Hello, world!'end program hello OR (FORTRAN 77 and prior) PROGRAM HELLO PRINT *, 'Hello, world!' END G Game Maker Languagestr='Hello, world!' //Using the show_message() function:show_message(str); //Using the draw_text() function:draw_text(0,0,str); Gopackage main import "fmt" func main() { fmt.Println("Hello, world!")} Groovy H Haskellmain = putStrLn "Hello, world!" HOP(define-service (hello-world) (<HTML> (<HEAD> (<TITLE> "Hello, world!")) (<BODY> "Hello, world!"))) HTML<!DOCTYPE html><html><body>Hello, world!</body></html> I IDLprint, "Hello, world!"end Io ISLISP(format (standard-output) "Hello, world!") J J 'Hello, world!' Javapublic class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); }} JavaScriptTo write to an HTML document: document.write('Hello, world!'); To display an alert dialog box: To write to a console/debugging log: console.log('Hello, world!'); Using Mozilla's Rhino: Using Windows Script Host: WScript.Echo("Hello, world!"); K KotlinMain article: Kotlin (programming language) package hello fun main(args : Array<String>) { println("Hello, world!")} L Linden Scripting LanguageMain article: Linden Scripting Language (programming language) llSay(0,"Hello, world!");llShout(0, "Hello, world!");llSayRegion(0, "Hello, world!"); Lisp Logo Lua M M4Hello, world! Malbolge('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#"`CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@> MathematicaMain article: Mathematica Maple MATLAB mIRC Script MUMPSmain() write "Hello, world!" quit O OberonMain article: Oberon programming language MODULE Hello; IMPORT Out;BEGIN Out.String("Hello, world!"); Out.LnEND Hello. Obixsystem.console.write_line ( "Hello, world!" ) Objective-CMain article: Objective-C#import <stdio.h> int main(void){ printf("Hello, world!\n"); return 0;} Otherwise (by gcc on pre-OpenStep/Apple Object based runtime): #import <stdio.h>#import <objc/Object.h> @interface Hello: Object- (void) say;@end @implementation Hello- (void) say { printf("Hello, world!\n");}@end int main() { Hello *hello = [Hello new]; [hello say]; [hello free]; return 0;} Pre-Modern (post-1994 OpenStep based Foundation APIs: @interface Hello:NSObject- (void) say;@end@implementation Hello- (void) say { NSLog(@"Hello, world!");}@end int main(int argc, char *argv[]){ NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init]; Hello *hello = [Hello new]; [hello say]; [hello release]; [p release]; return 0;} Modern (llvm, ARC memory management): @interface Hello:NSObject- (void) say;@end@implementation Hello- (void) say { NSLog(@"Hello, world!");}@end int main(int argc, char *argv[]){ @autoreleasepool {; [[Hello new] say]; } return 0;} OCaml print_endline "Hello, world!" OpaA "hello world" web server: Server.start(Server.http, { title: "Hello, world!", page: function() { <>Hello, world!</> } }) OrielMessageBox(OK, 1, INFORMATION, "Hello, world!", "Oriel Says Hello", ResponseValue) P Pascalprogram HelloWorld;uses crt; begin WriteLn('Hello, world!');end. Pawnmain(){ print("Hello, world.");} Perl 5Or use v5.10;say 'Hello, world!'; PHP<?php echo 'Hello, world!' ?> or <?php print 'Hello, world' ?> or PL/SQLSET SERVEROUTPUT ON;BEGIN DBMS_OUTPUT.PUT_LINE('Hello, world!');END; PowerShell Prologmain :- write('Hello, world!'), nl. Python 2 Python 3 PythonectMain article: Pythonect (programming language) R Rcat('Hello, world!\n') RacketTrivial "hello world" program: Running this program produces "Hello, World!" . More direct version: #lang racket(display "Hello, world!") 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"))))} REXXsay Hello, world! RPL<< "Hello, world!" MSGBOX >> RTL/2TITLE Hello, world!;LET NL=10;EXT PROC(REF ARRAY BYTE) TWRT;ENT PROC INT RRJOB(); TWRT("Hello, world!#NL#"); RETURN(1);ENDPROC; Ruby Rustfn main() { io::println("Hello, world!");} S Scalaobject HelloWorld extends App { println("Hello, world!")} Scheme(display "Hello, world!") ShellMain article: Bourne shell SimulaBegin OutText ("Hello, world!"); Outimage;End; SmalltalkTranscript show: 'Hello, world!'. SNOBOL OUTPUT = 'Hello, world!'END SpeakeasyAs an interactive statement : "Hello, world!" As a program : program hello "Hello, world!"end SQLSELECT 'Hello, world!' FROM DUMMY; -- DUMMY is a standard table in SAP HANA.SELECT 'Hello, world!' FROM DUAL; -- DUAL is a standard table in Oracle.SELECT 'Hello, world!' -- This will work in SQL Server. SmalltalkTranscript show: 'Hello, world!'. Stata T Tcl TI-BASICDisp "Hello, world!" U UnrealScriptMain article: UnrealScriptLog("Hello, world!"); V Valavoid main (){ print ("Hello, world!\n");}
Verilogmodule hello(); initial begin $display("Hello, world!"); $finish;end endmodule VHDLentity hello_world isend; architecture hello_world of hello_world isbegin stimulus : PROCESS begin assert false report "Hello, world!" severity note; wait; end PROCESS stimulus;end hello_world; Visual BasicMain article: Visual Basic Visual Basic .NETModule Module1 Sub Main() Console.WriteLine("Hello, world!") End SubEnd 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 SubEnd Class W WhitespaceThis example shows the program with syntax highlighting. Without highlighting, it would appear to be blank space.S S S TS S TS S S LTLS S S S S TTS S TS TLTLS S S S S TTS TTS S LTLS S S S S TTS TTS S LTLS S S S S TTS TTTTLTLS S S S S TS TTS S LTLS S S S S TS S S S S LTLS S S S S TTTS TTTLTLS S S S S TTS TTTTLTLS S S S S TTTS S TS LTLS S S S S TTS TTS S LTLS S S S S TTS S TS S LTLS S S S S TS S S S TLTLS S LLL External links
|
|