Scala is a general-purpose, high-level, multi-paradigm programming language. It is a pure object-oriented programming language which also provides support to the functional programming approach. Scala programs can convert to bytecodes and can run on the JVM (Java Virtual Machine). Scala stands for Scalable language. It also provides JavaScript runtimes. Scala is highly influenced by Java and some other programming languages like Lisp, Haskell, Pizza.
Evolution of Scala: Scala was designed by Martin Odersky, professor of programming methods at École Polytechnique Fédérale de Lausanne (EPFL) in Switzerland. He started to design Scala in 2001. Scala was first released publicly in 2004 on the Java platform as its first version, followed by version 2.0 in 2006.
- Easy to Start: Scala is a high-level language close to popular languages like Java, C, C++.
- Contains Best Features: Scala combines features of different languages like C, C++, Java.
- Close Integration with Java: Scala compiler can interpret Java classes and use Java libraries and tools; programs run on the JVM.
- Web & Desktop Development: Compiles to JVM bytecode (desktop/backend) and JavaScript (web).
- Used by Big Companies: Apple, Twitter, Walmart, Google and others use Scala for its scalability.
├── project.scala # scala-cli build config (Scala 3 + munit)
├── basics/ # Getting-started examples
│ ├── Hello.scala # Hello, World!
│ ├── ScalaExample.scala # Minimal object with main
│ ├── VarExp.scala # var/val and if-else
│ └── variables.scala # Values and expressions
├── features/ # Language feature examples
│ ├── CaseClasses.scala # Immutable data, copy, extractors
│ ├── PatternMatching.scala # Match expressions, guards, sealed traits
│ ├── HigherOrderFunctions.scala # compose, currying, pipelines, folds
│ ├── Collections.scala # List/Vector/Map/Set operations
│ ├── OptionHandling.scala # Option, for-comprehensions, no nulls
│ ├── TraitsAndOop.scala # Traits, sealed hierarchies, mixins
│ └── ExtensionsGivens.scala # Scala 3 extension methods & given/using
└── algorithms/
├── sorting/ # Bubble, Insertion, Selection, Merge, Quick
├── searching/ # Binary search, linear search
├── recursion/ # Factorial/Fibonacci/power, Tower of Hanoi
├── math/ # GCD/LCM, primes/sieve, number puzzles
├── strings/ # Palindromes, anagrams, string ops
└── datastructures/ # Functional stack, queue, linked list
Every example file is paired with a *.test.scala munit test suite.
- Scala CLI (
curl -sSLf https://scala-cli.virtuslab.org/get.sh | sh) - A JDK (17+ recommended; developed on JDK 21)
# Run any single example file
scala-cli run basics/Hello.scala
scala-cli run algorithms/sorting/MergeSort.scala
scala-cli run features/PatternMatching.scala
# Explore interactively
scala-cli console .# Run all test suites (150 tests)
scala-cli test .
# Run one suite
scala-cli test features/CaseClasses.test.scala
# Watch mode while learning
scala-cli test --watch .| Area | Examples |
|---|---|
| Basics | values vs variables, control flow |
| Features | case classes, pattern matching, higher-order functions, collections, Option, traits/OOP, extension methods & givens (Scala 3) |
| Sorting | bubble, insertion, selection, merge, quick (functional + in-place) |
| Searching | binary (iterative + tail-recursive), linear |
| Recursion | factorial, Fibonacci (naive vs fast), fast power, Tower of Hanoi |
| Math | GCD/LCM (Euclid), extended Euclid, primality, sieve of Eratosthenes, Armstrong/perfect numbers |
| Strings | palindrome checks, longest palindromic substring, anagrams, run-length encoding |
| Data Structures | persistent stack, amortized queue, singly linked list |