Dart Hello World Example – Step by Step Guide

0
1398
code dart hello world
example dart hello world

Dart is a powerful language backed by Google. Dart is such a scalable language even if you want to develop a mobile application, a web application or need a server-side script there is always a dart solution for that. Dart is backed by Google it means we can trust this language and it will stay around for a very long time. To learn this language we will start from dart hello world example and move to its full scale. To stay updated please bookmark this website and enable the notification.

For the development purpose we will use DartPad. Dartpad is an online editor. There are so many different ways to write and execute Dart code but online dartpad is the easiest one. For this course, we will follow the online dart editor but you are free to use any editor.

Dart Hello World

To write our first “hello world” example in Dart. First, we have to know how to write a print statement in Dart. This is how we write a print statement in Dart.

print("Hi Buddy. It's Waheed here.");

Cool? that’s it. Just write print and in brackets write the message you want to print.

Like any other programming language Dart also has an entry point. In Dart the entry point is main function. Start writing by void main the parentheses followed by curly brackets. Like this

void main() { }

Now every time Dart will execute the main function before anything else. As the setup is set now let’s complete the first Dart Hello World Example.

void main() {
  
    print("Dart: Hello World");
    
}

We can write as many print statements as many we want. Let’s write another print statement just to make sure it works perfectly fine.

void main() {
  
    print("Dart: Hello World");
    print("I am excited to learn more about dart"); 
}

Apart from strings, we can also print other data types. Let’s take an example of Integer data type. Now we have three print statements. As 15 is an integer we don’t have to enclose it with double quotes.

void main() {
  
    print("Dart: Hello World");
    print("I am excited to learn more about dart"); 
    print(15);
}

We can also perform some basic mathematical operations within a print statement. If you are not familiar with data types don’t worry We will go through all the data types in the upcoming articles.

void main() {
  
    print("Dart: Hello World");
    print("I am excited to learn more about dart"); 
    print(15);
    print(15/5);
}

and we can also print boolean values within print statement. Again if you are not aware of boolean or any other data type just stick with us and we will go through each and every data type.

void main() {
  
    print("Dart: Hello World");
    print("I am excited to learn more about dart"); 
    print(15);
    print(15/5);
    print(false);

}

I hope this article was good enough to explain some of the basic things about Dart. You can view this code directly in DartPad. Don’t forget to hit the “Run” button. You can change the print statement string with your name or whatever you like to print.

LEAVE A REPLY

Please enter your comment!
Please enter your name here