Scala is a statically-typed, multi-paradigm programming language that runs on the JVM, combining object-oriented and functional programming capabilities into a unified syntax. Designed by Martin Odersky and first released in 2003, Scala provides type inference, immutability by default, and powerful pattern matching, making it particularly well-suited for concurrent and distributed systems. Scala 3 (released 2021) brought sweeping improvements: a redesigned type system with union, intersection, and opaque types; first-class enums; a cleaner replacement for implicits via given/using; and optional indentation syntax. A key insight: Scala's expression-oriented design means nearly everything returns a value β there are no statements, only expressions β which encourages a more functional style and eliminates entire categories of bugs common in statement-based languages.
What This Cheat Sheet Covers
This topic spans 23 focused tables and 269 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Basic Syntax and Variables
| Keyword | Example | Description |
|---|---|---|
val x = 10 | β’ Immutable value β cannot be reassigned after initialization β’ preferred for most declarations | |
var y = 20y = 25 | β’ Mutable variable β can be reassigned β’ use sparingly when mutation is necessary | |
lazy val z = expensive() | Immutable value initialized only when first accessed β evaluation is deferred and cached | |
val name: String = "Alice" | Explicit type declaration β usually optional due to type inference | |
def helper(x: Int) = x + 1 def run() = println(helper(5)) | In Scala 3, definitions can appear outside any class or object β no wrapper required | |
def greet(name: String): Unit = println(s"Hello $name") | Marks a top-level method as program entry point β replaces object with main method |