Introduction
Every programming journey begins with a simple “Hello World” program. In Dart, this is incredibly straightforward and demonstrates the basic structure of a Dart application.The Hello World Program
Here’s the complete Hello World program in Dart:Understanding the Code
Let’s break down each part of this simple program:void main()
void main()
The
main() function is the entry point of every Dart application. When you run a Dart program, execution starts here.voidindicates that this function doesn’t return a valuemainis the required name for the entry point function()indicates this function takes no parameters (for now)
print()
print()
The
print() function displays output to the console.- It accepts a value (in this case, a String) as a parameter
- The text is enclosed in single quotes
'...'(you can also use double quotes"...") - Each statement in Dart ends with a semicolon
;
Running Your First Program
1
Create a file
Create a new file named
hello_world.dart in your project directory.2
Write the code
Copy the Hello World code into your file:
3
Run the program
Execute the program from your terminal:
4
See the output
You should see the output:
Try It Yourself
Modify the program to display your own message:Each
print() statement outputs text on a new line. You can call print() multiple times to display multiple lines of output.