On this page26 sections
- Prerequisites
- Connection With Previous Lectures
- Learning Objectives
- 1. What Is a Programming Language?
- 2. What Is Dart?
- 3. A First Look at Dart Code
- 4. Instructions Run in Order
- 5. Dart Can Calculate
- 6. A Short History of Dart
- 7. Where Dart Runs
- 8. How Dart Runs Your Code
- 9. Dart Checks Your Code Before It Runs
- 10. Null Safety in One Sentence
- 11. Dart and Flutter
- 12. Why Learn Dart?
- 13. How This Course Works
- 14. A Real-World Example
- Code Examples
- Common Beginner Mistakes
- Best Practices
- Mini Challenge
- Practice Questions
- Practice Answers
- Quick Revision
- Key Takeaways
- What's Next?
Lecture 01 — Introduction to Dart & Why Learn It
| Category | 1 — Dart Fundamentals |
| Lecture | 001 of 140 |
| Estimated video length | 14 min |
| Target | Dart 3.12.2 |
| Level | Beginner |
A computer does exactly what it is told, but it does not understand English. A programming language like Dart lets you write instructions that a person can read and a computer can follow.
Contents
Prerequisites · Connection · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Mini Challenge · Practice Questions · Answers · Takeaways
Every error message in this lecture is real. Each one was produced by running the code shown on Dart 3.12.2, so you will recognize it when you meet it yourself.
Prerequisites
This is the first lecture of the course. You need:
- a computer (Windows, macOS, or Linux)
- an internet connection
- no programming experience at all
You do not need Dart installed yet. The code in this lecture is a preview: read it now, and run it yourself after Lecture 002, which installs everything.
Connection With Previous Lectures
There is no previous lecture, so let us start with the problem every programmer faces.
Suppose Ali wants his computer to add up his three exam marks — 80, 75, and 85 — and show
the total. He could type "please add my marks" into the computer, and nothing would happen.
A computer cannot read ordinary language. It only follows precise instructions written in a
form it can process. To give it those instructions, Ali needs a programming language. This
course teaches one: Dart.
Learning Objectives
By the end of this lecture you will be able to:
- Explain what a programming language is
- Describe what Dart is and who created it
- Read a very small Dart program and predict its output
- List the platforms where Dart programs can run
- Explain, in simple terms, how Dart runs and compiles your code
- Describe how Dart catches mistakes before a program runs
- Explain the relationship between Dart and Flutter
- Give several practical reasons to learn Dart
1. What Is a Programming Language?
A programming language is a set of words and rules for writing instructions a computer can carry out. A file of those instructions is called a program, and writing it is called programming (or coding).
Analogy — think of a recipe. A recipe lists exact steps in a fixed order: "boil water, add rice, wait 15 minutes". The cook does not guess; they follow each step. A program is a recipe for the computer, and the programming language is the strict format the recipe must be written in.
There are many programming languages — Python, JavaScript, Java, Swift, Kotlin, and others. Each has its own words and rules. Dart is one of them.
2. What Is Dart?
Dart is a programming language created at Google. It is:
- general-purpose — you can build many kinds of programs with it, not just one kind
- free and open source — anyone can use it, read its source code, and contribute
- modern — it was designed recently, learning from older languages' mistakes
- type-safe — it checks your code for many mistakes before the program runs
Dart is best known as the language behind Flutter, Google's toolkit for building apps. This course teaches the Dart language itself — no Flutter — so that you understand the language completely before you use any framework built on it.
3. A First Look at Dart Code
Here is a complete Dart program:
void main() {
print('Hello, Dart!');
}Hello, Dart!The line print('Hello, Dart!'); tells the computer to display the text between the quotes.
Everything else is the frame that every Dart program needs. We will study main() and
print() line by line in Lecture 003. For now, just notice how readable it is.
4. Instructions Run in Order
A program can hold many instructions. Dart runs them one after another, from top to bottom:
void main() {
print('Hello, Dart!');
print('My name is Ali.');
print('I am learning to program.');
}Hello, Dart!
My name is Ali.
I am learning to program.Each print produces one line of output, in the same order as the code. Just like the recipe:
step one, then step two, then step three.
5. Dart Can Calculate
Computers are very good at arithmetic. Put a calculation inside print() — without quotes —
and Dart prints the result:
void main() {
print(2 + 3);
print(500 * 3);
print(10 / 4);
}5
1500
2.5* means multiply and / means divide. This is exactly what Ali needed: Dart can add his
marks for him. We will study arithmetic properly in Lecture 017 — Arithmetic & Assignment
Operators.
6. A Short History of Dart
| Year | Milestone |
|---|---|
| 2011 | Google announces Dart publicly |
| 2013 | Dart 1.0 — the first stable version |
| 2018 | Dart 2 — a stricter, safer type system; Flutter 1.0 is released |
| 2021 | Dart 2.12 — null safety arrives |
| 2023 | Dart 3 — null safety becomes mandatory; records and patterns arrive |
| Today | Dart 3.12 — the version this course targets |
You don't need to remember dates. The point is that Dart is mature — over a decade old — and still actively improved, with new versions released several times a year. We will look at how Dart versions work in Lecture 128 — Dart Language Evolution & Versioning.
7. Where Dart Runs
One language, many destinations:
| Platform | What you can build |
|---|---|
| Command line | tools and scripts that run in a terminal |
| Servers | back-end programs that answer requests from apps and websites |
| Web | programs that run in a browser (Dart is converted to JavaScript or WebAssembly) |
| Mobile & desktop | Android, iOS, Windows, macOS, and Linux apps, through Flutter |
In this course, every program runs on the command line. It is the simplest place to learn, because nothing distracts from the language itself. Everything you learn here carries over unchanged to the other platforms.
8. How Dart Runs Your Code
The computer's processor does not understand Dart directly. Your code has to be compiled — translated into instructions the machine can execute. Dart can do this in two ways:
- JIT (Just-In-Time) — while you are developing, Dart translates your code as it runs. You change a line, run it again, and see the result in seconds.
- AOT (Ahead-Of-Time) — when your program is finished, Dart translates all of it in advance into a fast, standalone program that starts instantly.
You get quick experiments while learning and fast programs when you ship. In this course, you
will mostly use the first way, with the dart run command. We will build standalone programs
with the Dart command-line tool in Lecture 113 — Dart CLI.
9. Dart Checks Your Code Before It Runs
Dart knows what kind of value each thing is — text or a number, for example — and refuses to mix them carelessly. This program tries to add a number to a piece of text:
void main() {
print('Total: ' + 5);
}Error: A value of type 'int' can't be assigned to a variable of type 'String'.
print('Total: ' + 5);
^The program never starts. Dart reports the mistake, points at it with ^, and waits for you
to fix it. Catching a mistake on your own screen is far better than having a user discover it
later. int and String are the names Dart uses for whole numbers and text — you will meet
them in Lecture 004.
10. Null Safety in One Sentence
Many programs crash because they try to use a value that is missing — in programming, a missing value is called null. Dart's null safety means the language tracks which values may be missing and makes you handle them, so this whole family of crashes is caught before the program runs. We will study it fully in Category 3, starting with Lecture 012 — Introduction to Null Safety.
11. Dart and Flutter
Flutter is a toolkit for building apps with buttons, screens, and animations. Flutter apps are written in Dart. Think of it this way: Dart is the language, and Flutter is one big project written in that language.
That makes the order of learning clear. If you know Dart well, Flutter is mostly about learning its building blocks. If you start Flutter without knowing Dart, you are learning two things at once, and every error message becomes harder to understand. This course gives you the language first.
12. Why Learn Dart?
- It is beginner-friendly. Dart's code reads cleanly, and its error messages say plainly what went wrong and where.
- One language, many platforms. The same skills work on the command line, servers, the web, and — with Flutter — phones and desktops.
- It opens the door to Flutter. Flutter is one of the most popular ways to build apps for Android and iOS from a single codebase, and companies hire Flutter developers.
- It catches mistakes early. Type safety and null safety find many bugs before your program runs.
- The tools are built in. Dart comes with a formatter, an analyzer that spots problems, a testing framework, and a package manager. Each one gets its own lecture in Categories 19 and 20.
- Skills transfer. Dart looks familiar to anyone who knows Java, JavaScript, C#, or Kotlin — and what you learn here will make those languages easier later.
- It is modern. Features such as records, patterns, and sealed classes (Category 13) let you write short, safe code.
13. How This Course Works
The course has 140 lectures in 23 categories, ordered so that every idea arrives only after everything it depends on. Each lecture follows the same plan:
- short lesson steps, each with a snippet and its real output
- ten complete code examples
- common mistakes, with the real error messages
- a mini challenge, practice questions, and answers at the end
The most important rule: type the code yourself. Reading a program is not the same as writing it. Your fingers will make small mistakes, Dart will report them, and fixing them is how you learn.
14. A Real-World Example
Sara runs a small stationery shop. A customer buys 3 notebooks at 500 each and 4 pens at 40 each. Here is a tiny Dart program that prints the receipt:
void main() {
print('Shop: Sara Stationery');
print('Notebook x 3');
print(500 * 3);
print('Pen x 4');
print(40 * 4);
print('Grand total:');
print(500 * 3 + 40 * 4);
}Shop: Sara Stationery
Notebook x 3
1500
Pen x 4
160
Grand total:
1660It combines everything from this lecture: instructions running in order, text in quotes, and
calculations without quotes. Dart multiplies before it adds, just as in school maths, so the
grand total is 1500 + 160. In Lecture 004 you will learn to store values like 500 in
variables, so a price is typed once instead of twice.
Code Examples
Each example is a complete program. After Lecture 002, copy one into a file and run it with
dart run.
Example 1 — Hello, World
void main() {
print('Hello, World!');
}Hello, World!Example 2 — Several Lines of Text
void main() {
print('Name: Sara');
print('City: Lahore');
print('Learning: Dart');
}Name: Sara
City: Lahore
Learning: DartExample 3 — Printing Numbers
void main() {
print(42);
print(3.14);
print(-7);
}42
3.14
-7Example 4 — Four Basic Calculations
void main() {
print(10 + 5);
print(10 - 5);
print(10 * 5);
print(10 / 5);
}15
5
50
2.0How it works
+,-, and*on whole numbers give whole numbers./always gives a decimal result, so10 / 5prints2.0, not2.- Lecture 009 — Numbers explains why.
Example 5 — Drawing with Text
void main() {
print('*****');
print('* *');
print('*****');
}*****
* *
*****Text inside quotes is printed exactly as written — spaces included.
Example 6 — Order Matters
void main() {
print('Step 1: Wake up');
print('Step 2: Open the laptop');
print('Step 3: Write Dart');
}Step 1: Wake up
Step 2: Open the laptop
Step 3: Write DartSwap two lines in the code and the output lines swap too.
Example 7 — Student Marks
void main() {
print('Student: Ali');
print('Total marks:');
print(80 + 75 + 85);
}Student: Ali
Total marks:
240How it works
- The first two lines print text, exactly as written.
- The third line has no quotes, so Dart calculates
80 + 75 + 85and prints the result. - This is the problem from the start of the lecture, solved.
Example 8 — Shopping Total
void main() {
print('Notebook: 500 each, 3 bought');
print('Total:');
print(500 * 3);
}Notebook: 500 each, 3 bought
Total:
1500How it works
- The numbers in the first line are inside quotes, so they are just text — Dart does not calculate anything there.
500 * 3is outside quotes, so Dart multiplies and prints1500.
Example 9 — Bank Balance
void main() {
print('Piggy bank: Zayan');
print('Starts at 150, gets 50, spends 30');
print(150 + 50 - 30);
}Piggy bank: Zayan
Starts at 150, gets 50, spends 30
170How it works
- Dart works through
150 + 50 - 30from left to right. 150 + 50is200, and200 - 30is170.
Example 10 — Temperature Conversion
void main() {
print('25 degrees Celsius in Fahrenheit:');
print(25 * 9 / 5 + 32);
}25 degrees Celsius in Fahrenheit:
77.0How it works
- The formula is: multiply by 9, divide by 5, add 32.
25 * 9is225, and225 / 5is45.0— a decimal, because of/.45.0 + 32is77.0.
Common Beginner Mistakes
1. Thinking Dart is only for Flutter
Flutter made Dart famous, but Dart runs on its own — on the command line, on servers, and on the web. Every program in this course runs without Flutter.
2. Writing Print with a capital P
void main() {
// Print('Hello, Dart!'); // ✗
}Error: Method not found: 'Print'.Dart is case-sensitive: print and Print are different names. Use lowercase print.
3. Forgetting the semicolon
void main() {
// print('Hello, Dart!') // ✗ no ; at the end
}Error: Expected ';' after this.Each instruction in Dart ends with ;, like a full stop at the end of a sentence.
4. Forgetting the quotes around text
void main() {
// print(Hello); // ✗
}Error: Undefined name 'Hello'.Without quotes, Dart thinks Hello is the name of something in your program — and there is
nothing called Hello. Text needs quotes: print('Hello');.
5. Trying to run code before installing Dart
If you type dart into a terminal before Lecture 002, you will see something like:
zsh:1: command not found: dartThat is not a mistake in your code — the computer simply doesn't have Dart yet. The exact wording depends on your operating system.
6. Trying to understand everything at once
You will see words like void and main before they are explained. That is normal. Each one
gets its own lecture. Focus on what the current lecture teaches.
Best Practices
- Type every example yourself instead of copying and pasting.
- Run the code, then change one thing and predict the new output before running it again.
- Read error messages slowly — Dart tells you what went wrong and points to where.
- Learn the language first; frameworks such as Flutter come afterwards.
- Study in order. Each lecture builds on the ones before it.
- Do the practice questions before opening the answers.
Mini Challenge
Write a welcome card for Sara. Print a greeting, a line listing her three test marks — 85,
90, and 78 — then let Dart calculate and print their total.
Your program should print exactly:
Welcome to the Dart course, Sara!
Your three test marks: 85, 90, 78
Total:
253Try it yourself before opening the solution.
Show solution
void main() {
print('Welcome to the Dart course, Sara!');
print('Your three test marks: 85, 90, 78');
print('Total:');
print(85 + 90 + 78);
}Welcome to the Dart course, Sara!
Your three test marks: 85, 90, 78
Total:
253How it works
- The first three lines are text in quotes, printed exactly as written.
- The last line has no quotes, so Dart adds
85 + 90 + 78and prints253.
Practice Questions
Work through these in order — they run from beginner to application to challenge. Write the programs now and run them after Lecture 002.
Beginner
- In one sentence, what is a programming language?
- Name the four kinds of platforms Dart programs can run on.
- What is the relationship between Dart and Flutter?
Application
-
Write a program that prints
Hello, Sara!. -
Write a program that prints three lines:
Name: Zayan,City: Karachi, andFavourite language: Dart. -
A shop sells a bag for
1200. Write a program that lets Dart calculate and print the cost of 3 bags. -
Predict the output of this program before checking the answer:
void main() { print(10 + 4); print(10 / 4); print(10 * 4); } -
This program has two mistakes. Find and fix them, so that it prints two lines:
void main() { Print('Dart is fun'); print('Ali is learning it') }
Challenge
- Water boils at
100degrees Celsius. Using the formula from Example 10, write a program that prints a label and then the temperature in Fahrenheit. Explain why the result ends in.0. - Zayan buys 3 notebooks at
500each and 2 pencils at20each, and pays with2000. Write a receipt program that prints each item with its cost, the total, and his change.
Practice Answers
Question 1 — Solution
A programming language is a set of words and rules for writing instructions that a computer can carry out.
Question 2 — Solution
The command line, servers, the web (in a browser), and mobile and desktop apps (through Flutter).
Question 3 — Solution
Flutter is a toolkit for building apps, and Flutter apps are written in Dart. Dart is the language; Flutter is built with it. You can use Dart without Flutter, but not Flutter without Dart.
Question 4 — Solution
void main() {
print('Hello, Sara!');
}Hello, Sara!Question 5 — Solution
void main() {
print('Name: Zayan');
print('City: Karachi');
print('Favourite language: Dart');
}Name: Zayan
City: Karachi
Favourite language: DartQuestion 6 — Solution
void main() {
print(1200 * 3);
}3600Question 7 — Solution
14
2.5
4010 / 4 gives a decimal result, 2.5. The other two lines give whole numbers.
Question 8 — Solution
Print must be lowercase, and the second line is missing its semicolon:
void main() {
print('Dart is fun');
print('Ali is learning it');
}Dart is fun
Ali is learning itQuestion 9 — Solution
void main() {
print('100 degrees Celsius in Fahrenheit:');
print(100 * 9 / 5 + 32);
}100 degrees Celsius in Fahrenheit:
212.0The calculation includes a division with /, and / always produces a decimal number. Adding
32 to a decimal number gives a decimal number, so the result prints as 212.0.
Question 10 — Solution
void main() {
print('Customer: Zayan');
print('Notebook x 3');
print(500 * 3);
print('Pencil x 2');
print(20 * 2);
print('Total:');
print(500 * 3 + 20 * 2);
print('Change from 2000:');
print(2000 - (500 * 3 + 20 * 2));
}Customer: Zayan
Notebook x 3
1500
Pencil x 2
40
Total:
1540
Change from 2000:
460The brackets in the last line make Dart calculate the whole total first, then subtract it from
2000. Notice that 500 * 3 + 20 * 2 is typed three times — exactly the kind of repetition
that variables remove in Lecture 004.
Quick Revision
- What is a program?
- Which company created Dart?
- In which order does Dart run the instructions in
main()? - What is the difference between
print('5 + 3')andprint(5 + 3)? - What is the difference between JIT and AOT compilation?
- When does Dart report a type mistake — before or while the program runs?
- What is null, and what does null safety do?
- Why does this course teach Dart before Flutter?
Key Takeaways
- A programming language is a precise way to give a computer instructions; a program is a file of those instructions.
- Dart is a free, open-source, general-purpose language created at Google.
- Dart runs instructions in order, top to bottom.
- Text goes inside quotes; a calculation without quotes is worked out and its result printed.
- Dart runs on the command line, servers, the web, and — through Flutter — mobile and desktop.
- Dart compiles JIT for fast development and AOT for fast finished programs.
- Type safety and null safety catch many mistakes before a program runs.
- Flutter is written in Dart, so learning Dart first makes Flutter far easier.
What's Next?
Lecture 02 — Dart SDK & Development Environment. You have now seen what Dart code looks like, but your computer cannot run it yet. Next we will install the Dart SDK, set up a code editor, and run our very first program for real.