1.3 Hello World
The following program prints "Hello World" after being compiled and run:
class Main {
static public function main():Void {
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 then 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 main Haxe class is the same as name of the class itself (in this case
Main.hx
).