易码技术论坛

 找回密码
 加入易码
搜索
查看: 208919|回复: 19

[分享]各种语言的Hello world program

[复制链接]
发表于 2005-1-17 20:52:00 | 显示全部楼层
Visual Basic

    MsgBox "Hello, world!"

Windows API (in C)

    #include

    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:


   

???

   
   

    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.

   

   


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


   
   
   
   

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

[此贴子已经被作者于2005-1-17 20:57:53编辑过]

发表于 2005-1-18 09:10:00 | 显示全部楼层
很全
不过没有MFC的,太大了
发表于 2005-1-18 09:20:00 | 显示全部楼层
洋洋,你好象发错地方了?
MM来帮忙移到编程版 去...................
发表于 2005-1-18 09:38:00 | 显示全部楼层
反正我记得文曲星上的说明书上写的:
GVBASIC
10:print"HELLO WORLD"
20:END
呵呵~
发表于 2005-1-19 14:10:00 | 显示全部楼层
<%
response.write "Hello world!"
%>
发表于 2005-1-20 01:54:00 | 显示全部楼层
用汉语说;“世界你好................”
发表于 2005-1-20 14:56:00 | 显示全部楼层
强啊!呵呵~这么多种语言啊!我用陕西话说:“你(ni)好(hao4)世(shi1)界(jie1):!”
发表于 2005-1-20 16:46:00 | 显示全部楼层
注意,此帖是严肃的-_-b
另外,在.net中,MessageBox.Show("Hello,world!")都可以用。
发表于 2006-5-27 21:11:00 | 显示全部楼层
呵呵,8楼的是陕西人吧,我们还是老乡呢。[em31]
发表于 2006-5-28 16:25:00 | 显示全部楼层
我原来申的一个空间里都是这玩艺~
发表于 2006-6-1 09:53:00 | 显示全部楼层
强,很多语言都没见过。
发表于 2006-6-1 15:29:00 | 显示全部楼层
LavaX:

void main()

{

printf("Hello,world.");

}
发表于 2006-6-1 20:07:00 | 显示全部楼层
呵 简单
发表于 2006-6-9 16:22:00 | 显示全部楼层
呵呵,这是我唯一能看懂得原代码
发表于 2006-6-11 14:48:00 | 显示全部楼层
用广州话说:

里(lei2)好(hou2)晒(shai1)届(gai1)

可能不是很标准,呵呵
发表于 2006-6-12 12:22:00 | 显示全部楼层
长沙话:ni0 hao1 si4 jie4
发表于 2006-7-3 09:27:00 | 显示全部楼层
天啊,我第一个程序(老师讲的)是:

10 LET A=1ET B=2

20 LET C=AET A=BET B=C

30 PRINT A,B

就是交换两个变量值,后来很长时间才知道,用swap就可以了,let还可以省略(羞愧中.......)

俺知道有hello world这样开始的方法,已经学了n长时间编程了,那时都参加过全国竞赛了,唉……大概就是竞赛和一般程序员的学习方法不同吧
发表于 2006-7-4 23:26:00 | 显示全部楼层
在Python中交换a,b俩变量只用
  1. a,b=b,a
复制代码

这么一行就搞定了。。
发表于 2006-7-5 04:18:00 | 显示全部楼层
不符合常规。只是一个噱头。语言还是如c一样语法简单好。
 楼主| 发表于 2005-1-17 20:52:24 | 显示全部楼层 |阅读模式
我们刚开始接触计算机语言大多从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

    HELL  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

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

C++
    #include
    using namespace std;

    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
                iBASIC_IO
        do
                !!io
                io.put_string("%N Hello, world!")
        end -- make
    end -- class HELLO_WORLD

Erlang
        -module(hello).
        -export([hello_world/0]).

        hello_world() -> ifwrite("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 hell
      PRINT "Hello, World"
    ENDP
Pascal
    program Hello;
    begin
        writeln('Hello, world!');
    end.
Perl
    print "Hello, world!\n";

PHP
    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
    #include
    #include
    #include
    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:lot(*this,
                                          &HelloWorld:n_button_clicked));
        add(m_button);
        m_button.show();
    }

    HelloWorld::~HelloWorld() {}

    void HelloWorld:n_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
    #include
    #include
    #include

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


您需要登录后才可以回帖 登录 | 加入易码

本版积分规则

Archiver|手机版|小黑屋|EMAX Studio

GMT+8, 2025-4-30 01:32 , Processed in 0.015714 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表