What Is Dart and How Do You Run It?
Dart in One Paragraph
Dart is a programming language: a set of rules for writing instructions that a computer can follow. Google created Dart and first released it in 2011. It was designed from the start to be pleasant for building user interfaces — the screens, buttons, and menus people interact with. Dart is the language behind Flutter, a popular toolkit for building apps that run on phones, web browsers, and desktop computers from a single set of code. If you have ever used an app built with Flutter, you have used a Dart program.
Dart is also a general-purpose language. You can write small scripts, command-line tools, and web servers with it. But its biggest strength, and the reason most people learn it, is building apps.
What Makes Dart Distinctive
Every language makes different choices. Here are the choices that shape how Dart feels to write:
- Statically typed. Dart checks your variables' types — such as text, whole numbers, or true/false values — while you write the code, before the program ever runs. If you try to add a number to a piece of text, Dart tells you immediately. This catches many mistakes early.
- Null safe. Dart makes you declare which values are allowed to be "nothing" (called null). If a variable might be empty, you must say so in the code, and the compiler then forces you to handle that case. This prevents one of the most common bugs in all of programming: using a value that does not exist.
- Compiled two ways. For daily development, Dart can compile just-in-time (JIT), which means it translates your code while the program runs. This makes a feature called hot reload possible: you change your code and see the result on screen almost instantly. For the final version of an app, Dart compiles ahead-of-time (AOT) into fast, native machine code — instructions the processor understands directly.
- Single-threaded with helpers. A Dart program normally does one thing at a time, in order. When it needs to wait — for a network response, for example — it uses mechanisms called Futures and Streams to wait without freezing the screen. For heavy work, it can spawn isolates, separate little workers that do not share memory. We will meet these later in the tutorial.
Where Dart Runs
Dart is not tied to one place. The same language can target several destinations:
| Target | How it runs | Typical use |
|---|---|---|
| Command line | The Dart virtual machine runs your code directly | Scripts, small tools |
| Mobile apps | Compiled ahead-of-time into native code | Flutter apps for iOS and Android |
| Web | Compiled to JavaScript, the language browsers understand | Flutter web apps |
| Servers | Runs on the Dart virtual machine on a server | APIs and backends |
The Dart virtual machine (VM) is a program that runs Dart code. Think of it as a friendly interpreter sitting between your code and the computer.
Installing Dart
To follow this tutorial you need the Dart software development kit (SDK) — a bundle containing the language tools, the VM, and a package manager (a tool for downloading reusable code others have written).
- Go to the official Dart site,
dart.dev, and open the "Get Dart" page. - Follow the instructions for your operating system. On Windows the easiest route is usually the installer; on macOS you can use Homebrew with
brew install dart; on Linux there are package instructions on the site. - Check that it worked. Open a terminal (a text window where you type commands) and type:
dart --versionYou should see something like Dart SDK version: 3.x.x. If you do, Dart is installed and ready.
Running Your First Dart Code
There are three main ways to run Dart, from quickest to most structured.
1. A quick experiment with `dart run`
Create a file named hello.dart containing one line:
void main() {
print('Hello, Dart!');
}A few things to notice, because they will appear in every Dart program you ever write:
mainis the entry point: the special function where Dart starts running your program. Every runnable Dart program has one.voidmeans this function returns nothing.printis a built-in instruction that writes text to the screen.- The semicolon ends the statement, and the curly braces group the function's code.
Run it from your terminal:
dart run hello.dartYou will see Hello, Dart! printed. That is a complete Dart program.
2. Trying ideas with `dart`
Sometimes you just want to test one line. Dart's REPL (a "read–evaluate–print loop," an interactive session where each line you type is run immediately) is handy for this:
dartThen type 2 + 2 and press Enter. Dart answers 4. This is a good scratch pad while learning.
3. A real project with `dart create`
For anything serious, Dart organizes code into a project — a folder with a standard structure and a file listing the project's dependencies (external packages it uses). Create one like this:
dart create my_app
cd my_app
dart rundart create makes a folder with a starter program inside. dart run executes the project's main program. Later chapters will use this structure throughout.
The Everyday Toolkit
The Dart SDK ships with more than a compiler. Three tools you will use constantly:
- dart run executes a file or project.
- dart analyze reads your code without running it and reports warnings and errors — like a helpful reviewer.
- dart format tidies your code's spacing and layout automatically, so every Dart program looks consistent.
There is also pub, Dart's package manager, which we cover in its own chapter near the end of the tutorial.
How a Dart Program Reaches the Screen
Here is the journey your code takes when you press run:
Show diagram source
flowchart LR
A[hello.dart source file] --> B[Dart compiler checks types and errors]
B --> C[Dart virtual machine]
C --> D[main function runs]
D --> E[Output printed to screen]The important part is step two: the compiler reads your code and complains about problems before anything runs. Later, when you meet Dart's type system, remember that this early checking is your safety net.
Why Learn Dart Now
Three practical reasons:
- Flutter's popularity. Flutter is one of the most used frameworks for cross-platform apps, and Dart is its only language. Learning Dart opens that door.
- Approachable syntax. If you have seen any modern language — JavaScript, Java, C# — Dart will feel familiar within a day.
- Strong safety features. Null safety and static types mean the compiler catches bugs that other languages let through until runtime, when users find them instead.
Getting Set for the Rest of the Tutorial
Before the next chapter, make sure you can do all three of these:
dart --versionprints a version number.- You can save a
.dartfile and run it withdart run. dart create scratch && cd scratch && dart runbuilds and runs a starter project.
With that in place, you are ready to write your first real programs.
Exercise
What is the special function where every runnable Dart program begins?
Show answer
The main function. Dart starts executing your program at the top of main, and every runnable program must define one.
Exercise
You change a line of Dart code and immediately want to see the result. Name two commands you could use, and describe when each is appropriate.
Show answer
For a single file or quick test, save the file and run dart run filename.dart. For quick one-off experiments, open the interactive session with the dart command and type expressions directly. For a full project, use dart run inside the project folder.
Exercise
What does it mean that Dart is "null safe," and why does that matter to you as a learner?
Show answer
Null safe means Dart requires you to declare which values may be absent (null), and the compiler forces you to handle those cases in your code. It matters because it catches "missing value" bugs before the program runs, rather than letting them crash later.
Spotted a mistake, or code that does not work?