Hello, World Program is a basic Simple First program or application to code and learn any new programming language.

It just displays the hello world string to the console.

This post shows how to write a Hello World application in Dart Programming language.

Dart Hello World example program

Following are steps to create a Hello World program in the Dart programming language

  • First, Open any source code editor
  • Create a file called HelloWorld.dart
  • Add the following code
//Hello World Sample First Program
void main() {
  print('Hello World First Program');
}

The above program contains three parts.

Comments : The comments are ignored by the compiler and provide a useful message about the line or block of a code.

 //Hello World Sample First Program

main(): It is a function called by dart runtime and Entry point for the dart program to execute.

Every dart executable code has a main() function and it does not take any arguments i.e. empty arguments. Every function in the dart has a return type. the main() function has a return type void. It does not return anything.

The function body is enclosed with {}

  • Print(): It is used to log the string or a message to the console. It is a standalone IO function.

Next, compile and run the program.

How to run the dart program

We can compile and run the program in many ways in Dart programming

  • Command-line

    • Open the terminal command line.

    • Go to the directory or folder where the program exists.

    • run the below command(dart HelloWorld.dart)

      A:\work\dart>dart HelloWorld.dart
      Hello World First Program
      
  • online browser dartpad

    • open dartpad in browser

    • Create a new Pad

    • Type the HelloWorld code or copy it

    • Click on the Run button on the opened pad.

    • you will see the Hello World First Program message in the Console window.

    • Source Code Editor or IDE

  • you can open any editor of your choice such as VSCode

  • Run inbuilt compiler support or open terminal and run as per command line