Hello world 프로그램
위키백과 ― 우리 모두의 백과사전.
Hello world 프로그램은, Hello, world!를 화면에 출력하는 컴퓨터 프로그램을 가리킨다. 이것은 프로그래밍 언어를 연습하는 데에 많이 쓰이고, 관습적으로 많은 프로그래밍 언어 서적에서 가장 처음 만들어보는 예제로 나온다.
이러한 프로그램은 프로그래밍 언어로 할 수 있는 간단한 것 중 하나로 여겨진다. 그러나, GUI를 사용할 때를 비롯하여, 어떤 경우에는 코드가 대단히 복잡해 질 수 있다. 또 다른 경우에는 프로그램 자체는 간단하지만 CLI 셸에서 입력해야 하는 파라미터가 많아 복잡한 경우도 있다. 또 임베디드 시스템에서는 글자들이 한정된 한두줄의 LCD에 표시될 것이다. 더욱 심한 경우에는 글자를 표시할 수 없어 Hello world! 대신에 간단하게 LED 점등을 할 수도 있다.
"hello world" 프로그램은 언어의 컴파일러, 통합 개발 환경, 런타임 환경이 정상적으로 작동하는지를 확인하는 sanity test로써 쓸모가 있다. 개발환경 구축에 필요한 툴체인을 바닥부터 구축하여 가장 간단한 프로그램을 컴파일하고 실행하기까지 상당한 작업이 필요하다. 따라서 새로운 툴체인을 테스트할 때에는 될 수 있는한 간단한 프로그램이 이용된다.
프로그래밍 할 수 있는 컴퓨터 개발에 있어서 작고 간단한 테스트용 프로그램이 이전에도 존재했지만, "Hello world!"를 사용하는 관습은 1978년에 출판된, 브라이언 커니핸과 데니스 리치가 쓴 "The C Programming Language"라는 책에서 비롯한다. 이 책에서 첫번째 예제 프로그램으로 hello, world 라는 문장을 출력했다. 모두 소문자이고, 느낌표도 없었다. 이 프로그램은 1974년의 벨 연구소에서 커니건이 써서 연구소 내에서 사용되던 작은 매뉴얼인 〈Programming in C: A Tutorial〉에 물려받은 것이다. 커니건의 버전은 다음과 같다.:
main( ) { printf("Hello, world!"); }
하지만, 처음으로 "hello"와 "world"를 같이 사용한 경우는 브라이언 커니건이 1973년도에 쓴 〈A Tutorial Introduction to the Language B〉에 등장한다. [1]
구두 방식이나 단락 방식에 따라서 여러 가지 방법이 존재하고, 출력 문장에서 몇몇 차이가 발생한다. 쉼표나 느낌표가 생략되는 경우도 있고, 'H'만이 대문자로 되거나 혹은 모두 소문자가 되는 경우도 있다. 원래 것과는 좀 달라졌지만, 가장 일반적인 문장은 "Hello, world!"이다. 몇몇 언어에서는 모든 문자를 대문자로 출력하여, "HELLO WORLD!"와 같은 결과가 나오기도 하고, 많은 난해한 프로그래밍 언어에서는 약간 변형된 문장을 출력하기도 한다. "Hello world" 프로그램은 보통은 스트링 끝이 개행 문자의 출력도 포함한다. (아스키 코드 10 혹은 13,10)
"hello world" 프로그램의 여러 가지 언어로 쓰여진 코드들의 모음은 여러 프로그래밍 언어들을 배우고 비교하는 데에 도움을 주는, 간단한 "로제타석"으로 사용할 수도 있다.
아래에 다양한 언어로 씌여진 예들이 있다.
[편집] 텍스트 기반 인터페이스
[편집] 4GL - Computer Associates with Ingres/DB
message "Hello, World!" with style = popup;
[편집] ABAP - SAP Aktiengesellschaft
REPORT ZELLO. WRITE 'Hello, World'.
[편집] ABC
WRITE "Hello, World!"
[편집] Ada
with Ada.Text_IO; Use Ada.Text_IO; procedure Hello is begin Put_Line ("Hello, world!"); end Hello;
For explanation see wikibooks:Programming:Ada:Basic.
[편집] 알골 68
In the popular upper-case stropping convention for bold words:
BEGIN print(("Hello, World!", newline)) END
or using prime stropping suitable for punch cards:
'BEGIN' PRINT(("HELLO, WORLD!", NEWLINE)) 'END'
or minimally using the short form of begin and end, and implied newline at program termination:
( print("Hello, World!") )
[편집] AmigaE
PROC main() WriteF('Hello, World!') ENDPROC
[편집] APL
'Hello World'
[편집] 어셈블리
[편집] 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 #$F3 @LP: LDA MSG-$F3,X ; load character JSR $FFD2 ; CHROUT (KERNAL), output to current output device (screen) INX BNE @LP ; RTS
[편집] Accumulator/Index microcoded machine: Data General Nova, RDOS
See the example section of the Nova article.
[편집] Expanded accumulator machine: 인텔 x86, DOS, TASM
MODEL SMALL IDEAL STACK 100H DATASEG MSG DB 'Hello, world!', 13, '$' 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
[편집] Expanded accumulator machine: 인텔 x86, Microsoft Windows, FASM
;Assumes that enviromnent variable %fasminc% is set format PE GUI 4.0 include '%fasminc%\win32a.inc' section '.code' code readable executable invoke MessageBox,0,hellomsg,hellolb,MB_OK+MB_ICONINFORMATION invoke ExitProcess,0 section '.data' data readable writable hellomsg db 'Hello, World!',0 hellolb db 'Hello World',0 data import library user32,'user32.dll',kernel32,'kernel32.dll' include '%fasminc%\apia\user32.inc' include '%fasminc%\apia\kernel32.inc' end data
[편집] Expanded accumulator machine: 인텔 x86, 리눅스, GAS
.data msg: .ascii "Hello, world!\n" len = . - msg .text .global _start _start: movl $len,%edx movl $msg,%ecx movl $1,%ebx movl $4,%eax int $0x80 movl $0,%ebx movl $1,%eax int $0x80
[편집] 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 fictional computer: MMIX, MMIXAL
string BYTE "Hello, world!",#a,0 string to be printed (#a is newline and 0 terminates the string) Main GETA $255,string get the address of the string in register 255 TRAP 0,Fputs,StdOut put the string pointed to by register 255 to file StdOut TRAP 0,Halt,0 end process
[편집] 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
[편집] AutoHotkey
MsgBox, "Hello, World!"
[편집] AutoIt
MsgBox(1,'','Hello, world!')
[편집] AWK
BEGIN { print "Hello, world!" }
[편집] 베이직
아래 예는 모든 ANSI/ISO 호환 베이직과 1970년대에서 1980년대에 마이크로 컴퓨터에 설치된 대부분의 베이직에서 동작한다.
10 PRINT "Hello, world!" 20 END
이러한 기종에 설치된 베이직은 줄번호가 생략된 즉각 모드로 실행할 수도 있다. 다음 예를 실행할 때에는 RUN 명령어가 필요없다.
PRINT "Hello, world!" ? "Hello, world!"
이후의 베이직은 구조화 프로그래밍을 지원하며 코드에서 줄번호가 사라졌다. 다음 예는 현대적인 베이직의 거의 대부분에서 RUN 명령으로 실행할 수 있다.
PRINT "Hello, world!" END
많은 베이직에서 End 선언문은 빼도 된다.
[편집] TI-BASIC
On TI calculators of the TI-80 through TI-86 range:
:Disp "HELLO, WORLD!" or :Output(1,1,"HELLO, WORLD!")
Or simply
:"HELLO, WORLD!"
On TI-89/TI-92 calculators:
:hellowld() :Prgm :Disp "Hello, world!" :EndPrgm
[편집] StarOffice/OpenOffice Basic
sub main print "Hello, World" end sub
[편집] Visual Basic
Sub Main MsgBox "Hello World!" End Sub
[편집] Visual Basic .NET
Module HelloWorldApp Sub Main() System.Console.WriteLine("Hello, world!") End Sub End Module
아니면 정의를 좀 다르게 하여,
Class HelloWorldApp Shared Sub Main() System.Console.WriteLine("Hello, world!") End Sub End Class
[편집] 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
[편집] boo
print "Hello, world!"
[편집] Casio fx-7950
This program will work on the fx-9750 graphing calculator and compatibles.
"HELLO WORLD"↵
[편집] C
#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
[편집] C#
class HelloWorldApp { static void Main() { System.Console.WriteLine("Hello, world!"); } }
[편집] C++
#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
[편집] C++/CLI
int main() { System::Console::WriteLine("Hello, world!"); }
[편집] C++, Managed (.NET)
#using <mscorlib.dll> using namespace System; int wmain() { Console::WriteLine("Hello, world!"); }
[편집] ColdFusion (CFM)
<cfoutput> Hello, world! </cfoutput>
[편집] COMAL
PRINT "Hello, World!"
[편집] 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 = "Hello, world"
[편집] CLIST
PROC 0 WRITE Hello, World!
[편집] Clipper
@1,1 say "Hello World!"
[편집] 코볼
IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "Hello, world!". STOP RUN.
[편집] D
import std.stdio; void main() { writefln("Hello, world!"); }
[편집] DC an arbitrary precision calculator
[Hello, world!]p
[편집] DCL batch
$ write sys$output "Hello, world!"
[편집] 딜런
module: hello format-out("Hello, world!\n");
[편집] 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#
print_endline "Hello world"
[편집] Factor
"Hello world" print
[편집] FOCAL
type "Hello, World!"!
or
t "Hello, World!"!
[편집] 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;
[편집] 포스
." Hello, world!" CR
[편집] 포트란
C234567 PROGRAM HELLO PRINT *, 'Hello, world!' 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")
Or to show a splash screen message:
show_message("Hello World")
[편집] Haskell
module Main (main) where main = putStrLn "Hello World"
[편집] Heron
program HelloWorld; functions { _main() { print_string("Hello, world!"); } } end
[편집] HP-41 & HP-42S
(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)
01 LBLTHELLO 02 THELLO, WORLD 03 PROMPT
[편집] HyperTalk (Apple HyperCard's scripting programming language)
put "Hello world"
[편집] 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
[편집] K
`0:"Hello world\n"
[편집] Kogut
WriteLine "Hello, world!"
[편집] Lisp
Lisp has many dialects that have appeared over its almost fifty-year history.
[편집] 커먼 리스프
(format t "Hello world!~%")
or
(write-line "Hello World!")
or merely:
"Hello World! "
Atoms are programs too!
[편집] Scheme
(display "Hello, world!") (newline)
[편집] 이맥스 리스프
(print "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!"
[편집] Macsyma, Maxima
print("Hello, world!")$
[편집] Maple
print("Hello, World!");
[편집] Mathematica
Print["Hello World"]
[편집] MATLAB
disp('Hello World')
[편집] Max
max v2; #N vpatcher 10 59 610 459; #P message 33 93 63 196617 Hello world!; #P newex 33 73 45 196617 loadbang; #P newex 33 111 31 196617 print; #P connect 1 0 2 0; #P connect 2 0 0 0; #P pop;
[편집] 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 3.0.)
@echo Hello, world!
[편집] MUF
: main me @ "Hello, world!" notify ;
[편집] Natural
WRITE "Hello, World!" END
[편집] Ncurses
#include <ncurses.h> int main() { initscr(); printw("Hello, world!"); refresh(); getch(); endwin(); return 0; }
[편집] Oberon
Oberon is both the name of a programming language and an operating system.
Program written for the Oberon operating system:
MODULE Hello; IMPORT Oberon, Texts; VAR W: Texts.Writer; PROCEDURE World*; BEGIN Texts.WriteString(W, "Hello World!"); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf) END World; BEGIN Texts.OpenWriter(W) END Hello.
Freestanding Oberon program using the standard Oakwood library:
MODULE Hello; IMPORT Out; BEGIN Out.String("Hello World!"); Out.Ln END Hello.
[편집] Objective C
[편집] Using the C library
#import <stdio.h> //An 객체지향 version. @interface Hello : Object { const char str[] = "Hello world"; } - (id) hello (void); @end @implementation Hello - (id) hello (void) { printf("%s\n", str); } @end int main(void) { Hello *h = [Hello new]; [h hello]; [h free]; return 0; }
[편집] Using OPENSTEP/Cocoa
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSLog(@"Hello, World!"); return 0; }
[편집] OCaml
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)) )
[편집] OPS83
module hello (main) { procedure main( ) { write() |Hello, world!|, '\n'; }; };
[편집] Pascal
Program Hello(output); begin WriteLn('Hello, world!'); end.
[편집] PBASIC
DEBUG "Hello, world!", CR
Or a blinking LED (it must be attached to the seventh output pin)
DO HIGH 7 'Make the 7th pin go high (turn the LED on) PAUSE 500 'Sleep for half a second LOW 7 ' Make the 7th pin go low (turn the LED off) LOOP END
[편집] Perl
print "Hello, world!\n";
(This is the first example in Learning Perl; the semicolon is optional.)
To access through the CGI:
#!/usr/bin/perl print "Content-type: text/plain\n\n"; print "Hello, world\n";
[편집] Perl 6
say "Hello World";
[편집] PHP
Hello, world!
or
<?php echo "Hello, world!\n"; ?>
or
<?="Hello, world!\n"?>
(Note: This will not work unless short open tags are enabled.
[편집] Pike
int main() { write("Hello, world!\n"); return 0; }
[편집] PL/SQL
procedure print_hello_world as dbms_output.enable(1000000); dbms_output.put_line("Hello World!"); end print_hello_world;
[편집] PL/I
Test: proc options(main) reorder; put skip edit('Hello, world!') (a); 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 } }
[편집] Processing
println("Hello world!");
thief(john). likes(mary, food). likes(mary, wine). likes(john, money). likes(john, X) :- likes(X, wine). may_steal(X, Y) :- thief(X), likes(X, Y).
[편집] 파이썬
print "Hello, world!"
[편집] REFAL
$ENTRY GO{=<Prout '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 >>
[편집] 루비
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!"); }
[편집] sed
(note: requires at least one line of input)
sed -ne '1s/.*/Hello, world!/p'
[편집] Seed7
$ include "seed7_05.s7i"; const proc: main is func begin writeln("Hello, world!"); end func;
[편집] Self
'Hello, World!' print.
[편집] Simula
BEGIN OutText("Hello World!"); OutImage; END
[편집] Smalltalk
Transcript show: 'Hello, world!'; cr
[편집] SML
print "Hello, world!\n";
[편집] 스노볼
OUTPUT = "Hello, world!" END
[편집] Span
class Hello { static public main: args { Console << "Hello World!\n"; } }
[편집] SPARK
with Spark_IO; --# inherit Spark_IO; --# main_program; procedure Hello_World --# global in out Spark_IO.Outputs; --# derives Spark_IO.Outputs from Spark_IO.Outputs; is begin Spark_IO.Put_Line (Spark_IO.Standard_Output, "Hello, world!", 0); end Hello_World;
[편집] SPITBOL
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 (for Oracle's PL/SQL proprietary procedural language)
BEGIN DBMS_OUTPUT.ENABLE(1000000); DBMS_OUTPUT.PUT_LINE('Hello World, from PL/SQL'); END;
or (e.g. MySQL or PostgreSQL dialect)
SELECT 'Hello, world!';
or (e.g. T-SQL dialect)
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 (Tool command language)
See also GUI section.
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!'
or
printf 'Hello, world!\n'
or for a curses interface:
dialog --msgbox 'Hello, world!' 0 0
[편집] 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!" (with no comma, as that would cause the synthesizer to pause)
say "Hello world!"
[편집] 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
[편집] Object Pascal (Delphi, Kylix)
Program Hello_World; uses Windows; Begin ShowMessage("Hello, world!"); End.
[편집] FLTK2 (in C++)
#include <fltk/Window.h> #include <fltk/Widget.h> #include <fltk/run.h> using namespace fltk; int main(int argc, char **argv) { Window *window = new Window(300, 180); window->begin(); Widget *box = new Widget(20, 40, 260, 100, "Hello, World!"); box->box(UP_BOX); box->labelfont(HELVETICA_BOLD_ITALIC); box->labelsize(36); box->labeltype(SHADOW_LABEL); window->end(); window->show(argc, argv); return run(); }
[편집] Gambas
See also TUI section.
PUBLIC SUB Main() Message.Info("Hello, world!") END
[편집] GTK+ (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 Python)
from gtk import * window = Window(WINDOW_TOPLEVEL) window.set_title("Hello World!") window.connect("destroy", main_quit) window.add(VBox()) window.child.pack_start(Label("Hello World!")) button=Button("OK") window.child.pack_end(button) button.connect("clicked", main_quit) window.show_all() main()
[편집] GTK# (in C#)
using Gtk; using GtkSharp; using System; class Hello { static void Main() { Application.Init (); Window window = new Window ("helloworld"); window.Show(); /* missing an OK button to quit maybe? Can anyone confirm? */ Application.Run (); } }
[편집] GTK+2.x (in Euphoria)
include gtk2/wrapper.e Info(NULL,"Hello","Hello World!")
[편집] Java
See also TUI section.
import javax.swing.JOptionPane; public class Hello { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Hello, world!"); } }
[편집] 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와 JScript
- JavaScript (an implementation of ECMAScript) 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(); return false;">Hello World Example</a>
- An easier method uses JavaScript implicitly, directly calling the reserved alert function. Cut and paste the following line inside the <body> .... </body> HTML tags.
<a href="#" onclick="alert('Hello, world!'); return false;">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!');
- There are many other ways:
javascript:document.write('Hello, world!\n');
[편집] K
This creates a window labeled "Hello world" with a button labeled "Hello world".
hello:hello..l:"Hello world" hello..c:`button `show$`hello
[편집] OPL
See also TUI section.
(On Psion Series 3 and later compatible PDAs.)
PROC guihello: ALERT("Hello, world!","","Exit") ENDP
or
PROC hello: dINIT "Window Title" dTEXT "","Hello World" dBUTTONS "OK",13 DIALOG ENDP
[편집] Qt (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 >>
[편집] RTML
Hello () TEXT "Hello, world!"
[편집] SWT
import org.eclipse.swt.SWT; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Label; public class SWTHello { public static void main (String [] args) { Display display = new Display (); final Shell shell = new Shell(display); RowLayout layout = new RowLayout(); layout.justify = true; layout.pack = true; shell.setLayout(layout); shell.setText("Hello, World!"); Label label = new Label(shell, SWT.CENTER); label.setText("Hello, World!"); shell.pack(); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
[편집] Tcl/Tk
See also TUI section.
label .l -text "Hello, world!" pack .l
[편집] Visual Basic including VBA
Sub Main() MsgBox "Hello, world!" End Sub
[편집] 윈도 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)>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 simply:
#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 with VBScript
<job id="HelloWorld"> <script language="VBScript"> WScript.Echo "Hello, world!" </script> </job>
[편집] Windows Script Host with JScript
<job id="HelloWorld"> <script language="JScript"> WScript.Echo( "Hello, world!" ) ; </script> </job>
[편집] 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
Type the following in a text file (e.g. hello.world.xul) and then open with Mozilla Firefox.
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <box align="center" pack="center" flex="1"> <description>Hello, world</description> </box> </window>
[편집] 난해한 프로그래밍 언어
See: Hello world program in esoteric languages
[편집] 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
The following sequence of characters, expressed as binary numbers (with cr/nl as above, and the same ordering of bytes):
00–07: 01001000 01100101 01101100 01101100 01101111 00101100 00100000 01110111 08–0E: 01101111 01110010 01101100 01100100 00100001 00001101 00001010
[편집] LaTeX
\documentclass{article} \begin{document} Hello, world! \end{document}
[편집] 마이크로소프트 워드
Opening Microsoft Word 8.0, typing "Hello, world!" and exiting (with saving the changes), creates the following 19 kB file (contents given in hexadecimal and ASCII representation):
00000000 d0 cf 11 e0 a1 b1 1a e1 00 00 00 00 00 00 00 00 |ÐÏ.ࡱ.á........| 00000010 00 00 00 00 00 00 00 00 3e 00 03 00 fe ff 09 00 |........>...þÿ..| 00000020 06 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 |................| 00000030 21 00 00 00 00 00 00 00 00 10 00 00 23 00 00 00 |!...........#...| 00000040 01 00 00 00 fe ff ff ff 00 00 00 00 20 00 00 00 |....þÿÿÿ.... ...| 00000050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ| ... 00000200 ec a5 c1 00 59 00 0c 04 00 00 00 12 bf 00 00 00 |ì¥Á.Y.......¿...| ... 00000550 00 00 f0 92 3b 3e e6 78 c5 01 9c 00 00 00 00 00 |..ð.;>æxÅ.......| 00000560 00 00 9c 00 00 00 00 00 00 00 ca 00 00 00 00 00 |..........Ê.....| 00000570 00 00 56 01 00 00 00 00 00 00 00 00 00 00 00 00 |..V.............| 00000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000590 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000600 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 a0 21 0d 0d |Hello, world !..| 00000610 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| ... 00002300 0b 00 00 00 4e 6f 72 6d 61 6c 2e 64 6f 74 00 64 |....Normal.dot.d| 00002310 1e 00 00 00 04 00 00 00 4d 46 48 00 1e 00 00 00 |........MFH.....| 00002320 02 00 00 00 31 00 49 00 1e 00 00 00 13 00 00 00 |....1.I.........| 00002330 4d 69 63 72 6f 73 6f 66 74 20 57 6f 72 64 20 38 |Microsoft Word 8| 00002340 2e 30 00 00 40 00 00 00 00 8c 86 47 00 00 00 00 |.0..@......G....| 00002350 40 00 00 00 00 f2 01 d7 e5 78 c5 01 40 00 00 00 |@....ò.×åxÅ.@...| 00002360 00 7e 88 1e e6 78 c5 01 03 00 00 00 01 00 00 00 |.~..æxÅ.........| 00002370 03 00 00 00 02 00 00 00 03 00 00 00 0d 00 00 00 |................| 00004810 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ| ... 00004a00 01 00 fe ff 03 0a 00 00 ff ff ff ff 06 09 02 00 |..þÿ....ÿÿÿÿ....| 00004a10 00 00 00 00 c0 00 00 00 00 00 00 46 18 00 00 00 |....À......F....| 00004a20 44 6f 63 75 6d 65 6e 74 20 4d 69 63 72 6f 73 6f |Document Microso| 00004a30 66 74 20 57 6f 72 64 00 0a 00 00 00 4d 53 57 6f |ft Word.....MSWo| 00004a40 72 64 44 6f 63 00 10 00 00 00 57 6f 72 64 2e 44 |rdDoc.....Word.D| 00004a50 6f 63 75 6d 65 6e 74 2e 38 00 f4 39 b2 71 00 00 |ocument.8.ô9²q..| 00004a60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| ... 00004bf0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00004c00
[편집] XHTML 1.1
(Using UTF-8 character set.)
<?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>
[편집] Page description languages
[편집] HTML
(simple)
<html><body> <h1>Hello, world!</h1> </body></html>
단순한 테스트를 위해서라면 <html> 과 <body> 택은 없어도 된다. 이 두가지 택을 쓰지 않은 예는 다음과 같다.
<pre>Hello, World!</pre>
또 일반 텍스트문서에 Hello, World! 라고 하고 볼 수도 있다.
[편집] HTML 4.01 Strict
(full)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello, World!</title> </head> <body> <p>Hello, world!</p> </body> </html>
HEAD 택은 생략될 수 있다. The global structure of an HTML document의 W3C 권고안 첫 문단은 바로 위 예를 들고 있다.
[편집] XSL 1.0
(UTF-8 문자집합을 사용.)
<?xml version="1.0" encoding="utf-8"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="utf-8" doctype-system="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd" doctype-pubilc="-//W3C//DTD XHTML 1.0 Strict//EN"/> <xsl:template match="/"> <html> <head> <title>Hello World</title> </head> <body> Hello World </body> </html> </xsl:template> </xsl:stylesheet>
[편집] PostScript
% Displays on console. (Hello world!) = % Displays as page output. /Courier findfont 24 scalefont setfont 100 100 moveto (Hello world!) show showpage
[편집] RTF
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier New;}} \f0\fs20 Hello, world! }
[편집] TeX
Hello World \bye