Dart Tutorials : How to write "Hello World" in Dart

At its heart, Dart is a conservative programming language. It was not designed to champion bold new ideas, but rather to create a predictable and stable programming environment. 

The language was created at Google in 2011, with the goal of unseating JavaScript as the language of the web.

JavaScript is a very flexible language, but its lack of a type system and misleadingly simple grammar can make projects very difficult to manage as they grow. 

Dart aimed to fix this by finding a halfway point between the dynamic nature of JavaScript and the class-based designs of Java and other object-oriented languages. 

The language uses a syntax that will be immediately familiar to any developer who already knows a C-style language.

Like all good programming books, we’re going to start with a program that prints “Hello, World” (kind of) to your console. In your favorite text editor, 

Create a new file in the hello_world directory called hello_world.dart. Write this code in the file:

void main() {
  print('Hello, Dart!');

Now, back in your terminal, you can execute Dart code with the CLI command dart. To follow along with these instructions, make sure you’re in the right project directory where your hello_world.dart file lives. Then, run the “Hello, Dart” example:

$ dart hello_world.dart
// => Hello, Dart!

If “Hello, Dart!” did in fact print, congrats!

You wrote your first Dart program, and you’re officially a Dart programmer!If “Hello, Dart!” did in fact print, congrats!

Let's understand how the Dart Works! 

The main function in Dart

All Dart functions look like this, but the main is special. It’s always the first code that’s executed in a Dart program. Your program must contain the main function that the Dart compiler can find.

The Void!

Notice the word void in the example. void is the return type of this function. If you haven’t used typed languages, this may look strange. 

The Print function!

Next in this example is the line that contains the print function:

print('Hello, Dart!');

print is a special function in Dart that prints text to the console.

On that same line, you have a String ('Hello, Dart!'), and you have a semicolon (;) at the end of the line. This is necessary at the end of every statement in Dart. That’s all you need to write a Dart program.

Hey I'm Venkat
Developer, Blogger, Thinker and Data scientist. nintyzeros [at] gmail.com I love the Data and Problem - An Indian Lives in US .If you have any question do reach me out via below social media