In this tutorial you will learn about the Dart Hello World Program and its application with practical example.
Dart Hello World Program
The “Hello world!” program is a simplest program that will display some text on the screen. The “Hello world!” program is a simple yet complete program for beginners that illustrates the basic syntax of any programming language. The “Hello world!” program gives you a way to test systems and programming environment. This tutorial will guide you through writing a basic “Hello, World” program in Dart Programming Language.
Prerequisites
Before starting with this tutorial we assume that you already have Dart SDK installed (If you do not have Dart SDK installed then install it before you get started) as well as a local programming environment must be set up on your computer.
Creating Dart Hello World Program
Step 1:- Create a file called “helloworld.dart” using a text editor program of your choice. The .dart file extension is used to specify a Dart Program file.
Step 2:- Let’s open the “helloworld.dart” file that we created, and put the following line of code in it and save it.
1 2 3 4 5 |
// W3Adda - Hello World Program // This is where the app starts executing. main(){ print("W3Adda - Hello World!"); } |
Let’s understand each and every part of the above program.
1. Comments – This is comment statements being used to provide information about the program we created.
1 2 |
// W3Adda - Hello World Program // This is where the app starts executing. |
2. main() – It is the entry point of our program from where the program execution begins. It is special, required, top-level function where execution of program begins.
3. print() – The print() function is used to output/display the content between double quotes to the screen. The print() method is similar to Perl, Java, or any other language.
Example:-
1 |
print("W3Adda - Hello World!"); |
Running Dart program
Step 3:- Now, compile and run above the Dart program
Once the program is executed it will print “Hello World!”.
Output:-