Introduction
Dart is a modern programming language developed by Google, designed for building scalable web, mobile, and server applications. Writing a “Hello World” program is the most basic way to start learning any language. In this guide, we’ll write a simple “Hello World” program in Dart, understand the structure of the code, and examine the output.
Dart Program: “Hello World”
Here’s the code to print “Hello World” in Dart:
void main() {
print('Hello, World!');
}
DartEXPLANATION OF THE CODE
void main()
:
This is the entry point of every Dart application. Themain()
function is where the execution starts. It doesn’t return any value, so it is declared asvoid
.{
and}
:
These curly braces define the start and end of themain()
function. All the instructions that need to be executed are placed inside these braces.print('Hello, World!');
:
Theprint()
function is used to output text to the console. Here, it prints the string'Hello, World!'
to the console. In Dart, strings are enclosed in single quotes ('
) or double quotes ("
), but in this case, we are using single quotes. The semicolon (;
) at the end of the line indicates the end of a statement.
Output
When you run this program, the following will be printed to the console:
Hello, World!
DartConclusion
This simple “Hello World” program in Dart provides an excellent starting point for beginners. It demonstrates how to define a function, use the print()
function, and write a basic Dart program. As you explore more advanced topics, understanding these fundamental concepts will serve as a foundation for learning the Dart programming language.
For more information about Dart, you can visit the official Dart website.