Dart Programming Tutorial 1.1 - Our First Program
-Last updated Sunday, March 24, 2013
Now that you have Dart installed, I bet that you can't wait to make your first program eh? Well then, let's dive right into it!
First of all, open DartEditor. Once this is done, click the "File" menu and select "New Application". Give it a meaningful name and select "Command-line application". Click Finish.
As you can see, the Editor has automatically created a basic command-line program (no graphical interface) that will display the text "Hello, World!" when you run it.
Click the green arrow to start the program.
As you can see, the text "Hello, World" now appears in our console!
Ok, so how does this work?
This is pretty much the simplest possible program in Dart. We start off with the line:
Void main() {
This line of code tells Dart to start executing the program from here. "Main" is the first function (more on those in the upcoming tutorials) that the program looks at when it starts. Notice the curly bracket "{" at the end of the line. Dart uses a syntax similar to most C-style languages in the sense that these brackets tell the compiler (the program that analyses your code) that everything between the opening and closing brackets is part of the "Main" function.
Lets move on to the second line:
print("Hello, World");
No, print doesn't actually "print" information on a piece of paper, rather, it prints text on the screen. In this case, everything that's between double quotes (") will be displayed when the program runs. Neat huh? We end this line of code with an semicolon. This tells the compiler we're ready to move on to another command.
Finally, we finish our program with a closing curly bracket (}), telling Dart that this is the end of the main function.