Scala Demo Examples
Practice programs, one file each. Every demo is self-contained, commented, and needs nothing but a JDK and
scala-cli — see Setup & Toolchain.
How to use: click View to open a file in the code viewer, read its comments, download it, then run it on your machine.
scala-cli run 01_hello.scala # compile and run a demo
scala-cli test 18_testing.scala # run the MUnit test demo
Foundations
Values, types, strings — the vocabulary of the language.
| # | Description | Link |
|---|---|---|
| 1 | Hello, World | View |
| 2 | Variables: val vs var | View |
| 3 | Scalar Types & Casting | View |
| 4 | Strings & Formatting | View |
Functions & Control Flow
Named and anonymous functions, branching, loops, and collections.
| # | Description | Link |
|---|---|---|
| 5 | Functions & Higher-Order Functions | View |
| 6 | if/else and match | View |
| 7 | for, while, labeled break | View |
| 8 | List, Map, Set & Pipelines | View |
Classes, Inheritance & Traits
The object-oriented side of Scala.
| # | Description | Link |
|---|---|---|
| 9 | Classes & Constructors | View |
| 10 | Inheritance & Override | View |
| 11 | Traits | View |
| 12 | Case Classes | View |
| 13 | Companion Objects | View |
Generics & Functional Error Handling
Type parameters, algebraic data types, and Option/Try/Either.
| # | Description | Link |
|---|---|---|
| 14 | Option, Try & Either | View |
| 15 | Generics | View |
| 16 | Sealed Traits & Exhaustive Matching | View |
Professional
Futures and tests — the skills a production codebase expects.
| # | Description | Link |
|---|---|---|
| 17 | Concurrency with Future | View |
| 18 | Unit Tests (MUnit) | View |
Study Projects
Small programs that compose several lessons into one working piece.
| # | Description | Link |
|---|---|---|
| 19 | Word Frequency Counter | View |
| 20 | In-Memory Todo List | View |
Practice move: after running each demo, change one thing on purpose — drop a
case from a sealed trait match, call .get on a None, remove the implicit ExecutionContext — and read the compiler or runtime error before fixing it.