HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DartVariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Map
🔀 Condition & Loop
🧩 Function
Dart›Introduction to Dart

Introduction to Dart

First step into modern Dart, the language of Flutter: the main function, printing with print, and comments.

Simple enough for a 5-year-old to understand

Every program starts with main

In Dart, a program starts running from the main() function. The print command outputs to the screen and moves to the next line.

Your first program
1
void main() {
The program starts from here. void = no return value.
FunctionThe program starts from here. void = no return value.
2
print("Hello!");
Prints to the screen. A semicolon (;) is mandatory at the end of the line.
Output / InputPrints to the screen. A semicolon (;) is mandatory at the end of the line.
3
}
End of the main function.
FunctionEnd of the main function.
FunctionOutput / Input
💡 Hint: In Dart, every line ends with a semicolon (;).

Comment lines

Example code
1
void main() {
2
// This is a comment — it doesn't run.
Single-line comment with //.
CommentSingle-line comment with //.
3
print("Code here");
Only this line runs.
Output / InputOnly this line runs.
4
}
CommentOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.From which function does a Dart program start running?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

Dart is a programming language developed by Google and the foundation upon which Flutter is built. It has rapidly gained popularity in recent years thanks to its ability to produce Android, iOS, web, and desktop applications from a single codebase.

Dart's design is intended to feel familiar: anyone who knows C, Java, or JavaScript can grasp its syntax in a few hours. But underneath lie two key features — hot reload during development and compilation to native machine code upon release.

Dart's most prominent modern feature is null safety. You explicitly state in the type whether a variable can be null; if you don't, the compiler disallows null values. This preemptively eliminates the most common cause of crashes in mobile apps.

What you will learn

  • the entry point of a Dart program
  • printing to the screen with print
  • The necessity of the semicolon
  • String interpolation syntax
  • Writing comment lines

Who is this for?

  • Those who want to develop mobile apps with Flutter
  • Those targeting multiple platforms with a single codebase
  • Those transitioning from Java or JavaScript

When to use?

In practice, Dart is used alongside Flutter: mobile, web, and desktop interfaces are written in the same language.

There is no special advantage to using Dart outside of Flutter; the ecosystem for server-side is limited and other languages are more mature.

Common mistakes

Wrong

void main() {
  print("Hello")
}

Every statement in Dart ends with a semicolon; this code will throw the "Expected to find ';'" error. Those coming from JavaScript or Python might think the end of a line is enough. Dart is not flexible in this regard; the semicolon is a mandatory part of the language.

Correct

void main() {
  print("Hello");
}

Wrong

void baslangic() {
  print("Hello");
}

A Dart program always starts from the main function; if you give it another name, the runner cannot find the entry point and says "Error: Cannot find 'main'". The function name must be exactly main.

Correct

void main() {
  print("Hello");
}

Wrong

void main() {
  var name = "Ayşe";
  print("Merhaba name");
}

To embed a variable's value into text, a dollar sign is required before its name; otherwise, it will literally print "Hello name" to the screen. Since this does not trigger a compilation error, such mistakes are only noticed by looking at the output.

Correct

void main() {
  var name = "Ayşe";
  print("Merhaba $name");
}

Frequently asked questions

Is Flutter required to learn Dart?

No, you can learn the language on its own and write command-line programs. However, Dart's primary use case today is largely Flutter; learning Flutter will be the natural next step after learning the language.

Should I use single quotes or double quotes?

There is no semantic difference between the two. Dart's official style guide recommends single quotes; the important thing is to be consistent within the project. If your text contains a quote, using the other type saves you from escaping characters.

How does Dart code work?

During development, it is interpreted on a virtual machine, which enables hot reload. When releasing, it compiles to native machine code or JavaScript for the web. Having both modes together is Dart's most practical aspect.

Summary

The program starts from the main function.

Every statement ends with a semicolon.

print outputs to the screen.

The dollar sign is used to embed values into text.

Dart is both interpreted and compiled.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code