1.3 Hello World

The following program prints "Hello World" after being compiled and run:

    Multi-line comments for documentation.
class Main {
    static public function main():Void {
        // Single line comment
        trace("Hello World");

This can be tested by saving the above code to a file named Main.hx and invoking the Haxe Compiler like so: haxe --main Main --interp. It generates the following output: Main.hx:3: Hello world. There are several things to learn from this:

  • Haxe programs are saved in files with an extension of .hx.
  • The Haxe Compiler is a command-line tool which can be invoked with parameters such as --main Main and --interp.
  • Haxe programs have classes (Main, upper-case), which have functions (main, lower-case).
  • The name of the file containing a Haxe class is the same as the name of the class itself (in this case Main.hx).
Related content