`
happmaoo
  • 浏览: 4337847 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

茶余饭后来回顾我们熟悉的“Hello world program”

阅读更多

我们刚开始接触计算机语言大多从Hello world 开始,下面演示各种语言的Hello world program:

AKA 控制台

  • ABC

WHILE (1=1) :

 WRITE "Hello World " 
  • Ada

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

  • AmigaE

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

  • APL

'Hello World'

  • Assembly language

Accumulator-only architecture: DEC PDP-8, PAL-III assembler
See the Example section of the PDP-8 article.


  • Accumulator + index register machine: MOS 6502, CBM, ca65 asm

MSG: .ASCIIZ "Hello, world!"
LDX #0
LDA MSG,X ; load initial char
@LP: JSR $FFD2 ; CHROUT CBM KERNAL
INX
LDA MSG,X
BNE @LP
RTS
Accumulator/Index microcoded machine: Data General Nova, RDOS
See the example section of the Nova article.
Expanded accumulator machine: Intel x86, MS-DOS, TASM

MODEL SMALL
IDEAL
STACK 100H

DATASEG
MSG DB 'Hello, world!$'

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

  • 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: VAX, VMS, MACRO32
.title hello
term_name: .ascid /SYS$INPUT/
term_chan: .blkw 1
out_iosb: .blkq 1
msg: .asciz /Hello, world!/

.entry start,0

; establish a channel for terminal I/O
$assign_s devnam=term_name,-
chan=term_chan
blbc r0,error

; queue the I/O request
$qio_s chan=term_chan,-
func=#io$_writevblk,-
iosb=out_iosb,-
p1=msg,-
p2=#13
blbc r0,error

$exit_s ; normal exit

error: halt ; error condition

.end start

  • AWK

BEGIN { print "Hello, world!" }

  • BASIC
  • MS BASIC (traditional, unstructured)
    10 PRINT "Hello, world!"
    20 END
  • TI-BASIC
    咧嘴笑脸isp "Hello, world!"
  • Structured BASIC
    print "Hello, world!"
  • BCPL
    GET "LIBHDR"

LET START () BE
$(
WRITES ("Hello, world!*N")
$)


  • C

#include <stdio.h></stdio.h>

int main(void) {
printf("Hello, world!\n");
return 0;
}

  • C++

#include <iostream><br> using namespace std;</iostream>

int main() {
cout << "Hello, world!" << endl;
return 0;
}

  • C#

class HelloWorldApp {
public static void Main() {
System.Console.WriteLine("Hello, world!");
}
}

  • Clean

module hello

Start :: String
Start = "Hello, world"

  • CLIST

PROC 0
WRITE Hello, World!

  • COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.

ENVIRONMENT DIVISION.

DATA DIVISION.

PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.

  • Common Lisp

(format t "Hello world!~%")

  • 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").

  • Forth

." Hello, world!" CR

  • Fortran (偶大学学的课程)

PROGRAM HELLO
WRITE(*,10)
10 FORMAT('Hello, world!')
STOP
END

  • Haskell

module HelloWorld (main) where

main = putStr "Hello World\n"


  • Iptscrae

ON ENTER {
"Hello, " "World!" & SAY
}

  • Java

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

  • Logo

print [hello world!]

  • Lua

print "Hello, world!"

  • 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

  • MSDOS batch

@echo off
echo Hello, world!

  • OCaml
    let _ =
    print_endline "Hello world!";;
  • OPL
    PROC hello:
    PRINT "Hello, World"
    ENDP
  • Pascal
    program Hello;
    begin
    writeln('Hello, world!');
    end.
  • Perl

print "Hello, world!\n";

  • PHP

<?php <br /> print("Hello, world!");
?>

  • Pike
    #!/usr/local/bin/pike
    int main() {
    write("Hello, world!\n");
    return 0;
    }
  • PL/I

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

  • Python

print "Hello, world!"

  • REXX, also NetRexx and Object REXX

say "Hello, world!"

  • Ruby

print "Hello, world!\n"

  • Sather

class HELLO_WORLD is
main is
#OUT+"Hello World\n";
end;
end;

  • Scheme

(display "Hello, world!")
(newline)

  • sed (requires at least one line of input)

sed -ne '1s/.*/Hello, world!/p'

  • Self

'Hello, World!' uppercase print.


  • Smalltalk

Transcript show: 'Hello, world!'

  • SML

print "Hello, world!\n";

  • SNOBOL

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, more simply


print 'Hello, World.'

  • StarOffice Basic

sub main
print "Hello, World"
end sub

  • Tcl

puts "Hello, world!"

  • Turing

put "Hello, world!"

  • UNIX-style shell

echo 'Hello, world!'

  • Romanian pseudocode (UBB Cluj-Napoca)

Algoritmul Salut este:
fie s:="Hello, world";
tipareste s;
sf-Salut

  • 传统图形界面应用开发工具

  • C++ bindings for GTK graphics toolkit

#include <iostream><br> #include <gtkmm main=""><br> #include <gtkmm button=""><br> #include <gtkmm window=""><br> using namespace std;</gtkmm></gtkmm></gtkmm></iostream>

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:困惑的笑脸lot(*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;
}

  • Java

import java.awt.*;
import java.awt.event.*;

public class HelloFrame extends Frame {
HelloFrame(String title) {
super(title);
}
public void paint(Graphics g) {
super.paint礼品盒;
java.awt.Insets ins = this.getInsets();
g.drawString("Hello, world!", ins.left + 25, ins.top + 25);
}
public static void main(String args [])
{
HelloFrame fr = new HelloFrame("Hello");

fr.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit( 0 );
}
}
);
fr.setResizable(true);
fr.setSize(500, 100);
fr.setVisible(true);
}
}


  • Qt toolkit (in C++)

#include <qapplication.h><br> #include <qpushbutton.h><br> #include <qwidget.h><br> #include <iostream></iostream></qwidget.h></qpushbutton.h></qapplication.h>

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();
}

  • Visual Basic

MsgBox "Hello, world!"

  • Windows API (in C)

#include <windows.h></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, "Hello, world!", 13);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

基于web图形用户界面


  • Java applet

Java applets work in conjunction with HTML files.





HelloWorld Program says:


<applet height="100" width="600" code="HelloWorld"> <br>??? </applet>


import java.applet.*;
import java.awt.*;

public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello, world!", 100, 50);
}
}

  • JavaScript, aka ECMAScript

JavaScript is a scripting language used in HTML files. To demo this program Cut and Paste the following code into any HTML file.


???? function helloWorld()
???? {
???????? javascript: alert("Hello, world!");
???? }
????

onclick="javascript:helloWorld();">Hello World Example

An easier method uses JavaScript implicitly, calling the reserved alert function. Cut and paste the following line inside the .... HTML tags.

Hello World Example

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!')

  • XUL

<window there="" gatekeeper="" keymaster="" www="" http="" xmlns="&lt;A href=">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;<br><box align="center"><br><label value="Hello, world!"><br></label></box><br></window>

  • 文档格式
  • 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

  • HTML






Hello, world!

  • PostScript


/font /Courier findfont 24 scalefont
font setfont
100 100 moveto
(Hello world!) show
showpage

  • TeX

\font\HW=cmr10 scaled 3000
\leftline{\HW Hello world}
\bye



  


  
分享到:
评论

相关推荐

    learning-ionic

    #Learning Ionic Framework A Hello World Application 你了解多少种计算机语言?...专为程序猿量身打造,全面的语言百科,趣味的问答小游戏,茶余饭后,夜深人静,请来一打 Hello World ,不用客气!

    茶余饭后聊聊Vue3.0响应式数据那些事儿

    主要介绍了茶余饭后聊聊Vue3.0响应式数据那些事儿,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

    网络口碑营销人才:利用网络工具进行营销.pdf

    我们是 通过策划和创意,与众多大型网站、专业网站以及常规媒体建立合作关系, 利用搜索网站、论坛、博客、聊天工具等营销手段,并借助热点话题对企业 及产品进行有计划的网络炒作,让企业及产品自然而然成为老百姓...

    啊哈C!思考快你一步

    这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧。

    啊哈C!思考快你一步-用编程轻松提升逻辑力.pdf

    这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧!

    啊哈c语言pdf

    这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧

    啊哈C!思考快你一步——用编程轻松提升逻辑力(带书签)

    这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧。

    leetcode答案-Dalao:某群大佬茶余饭后的消遣

    leetcode 答案 每日一题(也称大佬带我装逼带我飞) 1. 这家前后端关系肯定好不到哪里去 出题人 B大 这段php代码 可能输出一个 JSON 也可能输出空 const foo = { bar: &lt;?php&gt; ...Chobits:这样写代

    人工智能 Java 调用百度AI、腾讯AI、腾讯优图、.rar

    现在混在职场,如果不懂一点人工智能...2、让你在茶余饭后闲谈时,参加大咖的AI交流沙龙时,面试Ai公司准备资料时,更熟悉和从容。 3、我希望用小白最能懂的话解释一些我们不懂的知识,因为我和你都是AI领域的修行者。

    Linux2.6.24内核注释

    这是半年来,在看ULA的过程中,针对Linux 2.6.24内核顺手做的一点注释。内容不多,个人觉得文件系统和USB这两个模块的注释还有一点意思。 所有注释都是中文,您可以与标准2.6.24内核进行比较,看看具体的注释内容。 ...

    [详细完整版]人工智能.docx

    一时间,人们茶余饭后的谈资都围绕着人工智能这一领域展开。对于人工智能来说,前60年的人工智能历程,可以用"无穷动"来形容;后60年的人工智能发展,可以用"无穷大"来期许。本文就从它的概念、简史、成果、前景、...

    类Unix系统--jiushitale

    每当我们想到Linux是我们就想到了这本书,每当烦恼分布式系统的实现时,我们就想到了这本书,每当茶余饭后无所事事时,我们就想起了这本书。你,我的朋友!看看吧

    疯人院 v1.0.4

    疯人院 v1.0.4 当前版本:1.0.4 软件语言:中文 ...我们会每天更新最优质的内容,以便您可以在茶余饭后等人等车上厕所发呆无聊的时候为自己找点乐子。 我们会保持功能的更新和优化,打造出一款优质的疯友软件。

    编码的奥秘

    编码的奥秘,文字版,带书签。这本书作为茶余饭后阅读是比较不错的。

    BlueStacks-ThinInstaller_0.7.0.722中文版 BlueStacks虚拟机

    BlueStacks是一款在PC上面运行,安装简单,功能强大的安卓软件模拟器,可以运行绝大多数安卓的应用,方便一般大众玩家的使用,是我们可以把那些经典的、好玩的软件搬到大屏幕的PC上来,再配合触控显示器,体验绝佳...

    逗你乐--捕获世间最新最全搞笑图片、段子、美女图、视频

    工作学习时 夜深人静时 无聊呆萌时 茶余饭后时 打开APP 开启您一天的快乐之旅吧 搞笑图片 爆笑段子 恶搞视频 美女图片 美女视频"&gt;这是一款休闲娱乐应用 含有Android个人开发者如何获取收益的例子 网罗世间最新最全...

    安卓系统PC模拟平台

    BlueStacks是一款在PC上面运行,安装简单,功能强大的安卓软件模拟器,可以运行绝大多数安卓的应用,方便一般大众玩家的使用,是我们可以把那些经典的、好玩的软件搬到大屏幕的PC上来,再配合触控显示器,体验绝佳的...

    新手帖关于PWM逆变器从论坛上DOWN了一个逆变器模型-PWM_Discrete.mdl

    新手帖关于PWM逆变器从论坛上DOWN了一个逆变器模型-PWM_Discrete.mdl 从网上DOWN了一个简单的逆变器模型,附件见下,我得PWM序列生产一个是用连续的,一个是用离散的,模型中...请高手们茶余饭后帮忙解答!小弟谢过!

Global site tag (gtag.js) - Google Analytics