void main() => print('Hello, World!');
Hello World in Dart was written by:
This article was written by:
If you see anything you'd like to change or update, please consider contributing.
Coming from a Java background, the following snippet of code is downright stripped to the barebones.
In order to implement Hello World in Dart, developers need to understand only
three concepts like
main methods, strings, and arrow functions. But look at the
code above, it seems deceptively easy, right?
What is going on is
main() only does one thing, print the phrase "Hello, World!".
We'll dig into how and why all of this happens in a bit, but it's important to
step away for a bit and just look at what's there and acknowledge how simple it is.
In a Dart project, only one class would have a main method (
method is how every Dart program knows where to start. Therefore, every program
must have exactly one of these
main methods implemented. Don't worry too much
about the syntax. Just know that we need a
Then we have to output our greeting ("Hello, World!") to the command line. To
do so, we have to leverage a static method out of Dart's built-in library. It's
main() only difference is we put a
string inside the parentheses. It tells the computer to take the string and
print out so we can read it.
The last concept are arrow functions (
=>). These are methods like
main that only do one thing. Because they only do one thing, we
=> from the method's definition (
main()) directly to the logic.
Other more complex methods may require the use of
return. But that's not
required in this case.
To run this program, just download the Dart interpreter. Then, run this:
Alternatively, you can use an online Dart interpreter.