Hello World in 40 Programming Languages

Hello World in 40 Programming Languages

Today I woke up and asked myself how many programming languages are out there. I find it really interesting that there are quite a few programming languages – with each one having various strengths and weaknesses. While it is good to know as many programming languages as possible, I believe it is more important to understand the fundamental concepts behind them. Examples of such concepts include: looping and conditional structures, sequence of commands, variables, primitive data types, and Object Oriented Programming (for some programming languages).

You may notice that some examples do not have syntax highlighting… At the moment, I’m using a WordPress plugin to manage this – called ‘SyntaxHighligher‘ by Alex Gorbatchev. It doesn’t seem to cover some of the languages listed here, so may be an opportunity to make some contributions…

With the above being said, I thought of exploring variants of the ever-so-popular “Hello World” program in 40 different programming languages. You can also view many more examples by going down to the sources section. Below are the 40 examples I have chosen:

  1. ActionScript3

    trace("Hello, World!");
    
    this.createTextField("hello_txt",0,10,10,100,20);
    this.hello_txt.text="Hello, World!";
    
  2. Ada

    with TEXT_IO;
    
    procedure HELLO is
    begin
     TEXT_IO.PUT_LINE ("Hello, World!");
    end HELLO;
    
  3. ASP.NET

    Response.Write("Hello, World!")
    
  4. Bash

    #!/bin/sh
    echo "Hello, World!"
    
  5. C# (C Sharp)

    using System;
    class HelloWorld
    {
     static void Main()
     {
     System.Console.WriteLine("Hello, World!");
     }
    }
    
  6. C

    #include 
    
    /* Hello */
    int main(void)
    {
     printf("Hello, World!");
     return 0;
    }
    
  7. Cobol

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    
    ENVIRONMENT DIVISION.
    
    DATA DIVISION.
    
    PROCEDURE DIVISION.
    DISPLAY "Hello, World!".
    STOP RUN.
    
  8. Cocoa (Objective C)

    #import <Cocoa/Cocoa.h>
    @interface hello : NSObject {
    }
    @end
    
    @implementation hello
    
    -(void)awakeFromNib
    { 
     NSRunAlertPanel(@"Message from your Computer", @"Hello, World!", @"Hi!",
     nil, nil);
    }
    
    @end
    
  9. Dart

    main() 
    {
      print('Hello, World!');
    }
    
  10. Delphi

    program Hello_World;
    uses 
     Windows;
    
    begin
     ShowMessage("Hello, World!");
    end.
    
  11. Erlang

    -module(hello).
    -export([hello_world/0]).
    
    hello_world() -> io:fwrite("Hello, World!\n").
    
  12. F#

    print_endline "Hello, World!"
    
  13. Fortran

    PROGRAM HELLO
     PRINT *, 'Hello, World!'
     END
    
  14. Go

    package main
    import fmt "fmt"
    
    func main() 
    {
       fmt.Printf("Hello, World!\n");
    }
    
  15. Gtk# in C#

    using Gtk;
    using GtkSharp;
    using System;
    
    class Hello {
     static void Main()
     {
       Application.Init ();
    
       Window window = new Window("");
       window.DeleteEvent += cls_evn;
       Button close = new Button ("Hello world");
       close.Clicked += new EventHandler(cls_evn);
    
       window.Add(close);
       window.ShowAll();
    
       Application.Run ();
     }
     static void cls_evn(object obj, EventArgs args)
     {
       Application.Quit();
     }
    }
    
  16. Gtk+ in C++

    #include 
    #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;
    }
    
  17. Haskell

    module Main (main) where
    
    main = putStrLn "Hello, World!"
    
  18. Java, Java Swing, Java SWT

    Java
    public class HelloWorld {
     public static void main(String[] args) {
     System.out.println("Hello, World!");
     }
    }
    
    Java Swing
    import javax.swing.JOptionPane;
    
    public class Hello 
    {
     public static void main(String[] args) 
     {
     JOptionPane.showMessageDialog(null, "Hello, World!");
     }
    }
    
    Java 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 ();
     }
    }
    
  19. JavaFX Script

    var win = new Frame();
    win.title = "Hello World!";
    win.width = 400;
    var label = new Label();
    label.text = "Hello World!";
    win.content = label;
    win.visible = true;
    
  20. JavaScript

    // Write to DOM
    document.write('Hello, World!');
    
    //Alert
    alert('Hello, World!');
    
  21. LaTex

    \documentclass{article}
    \begin{document}
     Hello, World!
    \end{document}
    
  22. Lisp

    (format t "Hello World!~%")
    
    (write-line "Hello World!")
    
  23. Matlab

    disp('Hello world')
    
  24. NewtonScript

    baseview :=
     {viewBounds: {left: -3, top: 71, right: 138, bottom: 137},
     viewFlags: 581,
     declareSelf: 'base,
     _proto: protoFloatNGo,
     debug: "baseview"
     };
    
    textview := * child of baseview *
     {text: "Hello World!",
     viewBounds: {left: 33, top: 24, right: 113, bottom: 46},
     viewFlags: 579,
     _proto: protoStaticText,
     debug: "textview"
     };
    
  25. Pascal

    program hello;
    
    begin
    writeln('Hello, World!');
    end.
    
  26. Pdf

    %PDF-1.0
    1 0 obj
    << /Type /Catalog /Pages 3 0 R /Outlines 2 0 R >>
    endobj
    2 0 obj
    << /Type /Outlines /Count 0 >>
    endobj
    3 0 obj
    << /Type /Pages /Count 1 /Kids [4 0 R] >>
    endobj
    4 0 obj
    <<
    /Type /Page
    /Parent 3 0 R
    /Resources << /Font << /F1 7 0 R >>/ProcSet 6 0 R
    >>
    /MediaBox [0 0 612 792]
    /Contents 5 0 R
    >>
    endobj
    5 0 obj
    << /Length 44 >>
    stream
    BT
    /F1 24 Tf
    100 100 Td (Hello World) Tj
    ET
    endstream
    endobj
    6 0 obj
    [/PDF /Text]
    endobj
    7 0 obj
    << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /MacRomanEncoding >>
    endobj
    xref
    0 8
    0000000000 65535 f
    0000000009 00000 n
    0000000074 00000 n
    0000000120 00000 n
    0000000179 00000 n
    0000000322 00000 n
    0000000415 00000 n
    0000000445 00000 n
    trailer
    << /Size 8 /Root 1 0 R >>
    startxref
    553
    %%EOF
    
  27. Perl

    # Hello
    print "Hello, World!\n";
    
  28. PHP

    <?php 
        echo "Hello world!";
    ?>
    
    //Or
    <?php 
        print 'Hello, World!' . PHP_EOL;
    ?>
  29. Powershell

    # Filename: Hello.ps1
    Write-Host
    Write-Host 'Hello World!'
    Write-Host "Good-bye World! `n"
    # end of script
    
  30. Python

    print "Hello, World!";
    
    print("Hello, World!") 
    
  31. Qt toolkit (C++)

    #include 
    #include 
    
    int main(int argc, char *argv[])
    {
      QApplication app(argc, argv);
      QLabel salut("Hello World!");
      salut.show();
      return app.exec();
    }
    
  32. Ruby

    puts "Hello, World!"
    
  33. Scala

    object HelloWorld extends Application {
     Console.println("Hello, World!");
    }
    
  34. Rust

    io::println("hello?");
    
  35. Smalltalk

    Transcript show: 'Hello, World!'; cr
    
  36. SQL

    CREATE TABLE message (text char(15));
    INSERT INTO message (text) VALUES ('Hello, World!');
    SELECT text FROM message;
    DROP TABLE message;
    
    #OR
    
    SELECT 'Hello, World!';
    
  37. SVG

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <svg width="240px" height="100px" viewBox="0 0 240 100" 
         xmlns="http://www.w3.org/2000/svg">
     <title>Hello World</title>
     <g>
     <text x="20" y="50">Hello World</text>
     </g>
    </svg>
  38. Swift

    println("Hello World!")
    
  39. VB.NET (Visual Basic .NET)

    Class HelloWorldApp
     Shared Sub Main()
     System.Console.WriteLine("Hello, World!")
     End Sub
    End Class
    
  40. XML

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="HelloWorld.xsl" ?>
    <!-- Hello in XML -->
    <text>
       <string>Hello, World!</string>
    </text>

Sources

Posted in ASP.NET, C#, H.T.M.L, Java, Linux, MySQL, Obejct Oriented Programming, PHP, PostgreSQL, Programming, Programming Languages, Python, Ruby on Rails, Software Development, Swift, Web Development Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
4 comments on “Hello World in 40 Programming Languages
  1. Gored says:

    Forth

    : HELLO .” Hello, World!” ;

  2. Mark Kennedy says:

    The Scala example is wrong. It has to be “extends App”, not “with App”.

  3. jiyinyiyong says:

    helloworld in CirruScript and Sepal.clj:

    “`cirru
    console.log “:Hello world!”
    “`
    “`cirru
    println “|Hello world!”
    “`

1 Pings/Trackbacks for "Hello World in 40 Programming Languages"
  1. […] Helloworld in 40 languages […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*