Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications

Categories

🎓 Certifications
🤖 Artificial Intelligence
☁️ Cloud and Infrastructure
💾 Data and Databases
💼 Professional Skills
🎯 Programming and Development
🔒 Security and Networking
📚 Specialized Topics
CheatGrid
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications
LVLEVEL 0
0/5 XP
GitHub
© 2026 CheatGrid™. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Scala Programming Language Cheat Sheet

Scala Programming Language Cheat Sheet

Back to Programming Languages
Updated 2026-04-27
Next Topic: String Processing and Text Manipulation Cheat Sheet

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 VariablesTable 2: Data TypesTable 3: String OperationsTable 4: Control FlowTable 5: Pattern MatchingTable 6: FunctionsTable 7: Collections — Lists and SequencesTable 8: Collections — Transformation MethodsTable 9: Collections — Sets and MapsTable 10: TuplesTable 11: Classes and ObjectsTable 12: TraitsTable 13: Enums (Scala 3)Table 14: Option, Either, and TryTable 15: For-ComprehensionsTable 16: Implicits (Scala 2)Table 17: Givens and Extensions (Scala 3)Table 18: Type SystemTable 19: ConcurrencyTable 20: AnnotationsTable 21: Package and ImportTable 22: Exception HandlingTable 23: Advanced Features

Table 1: Basic Syntax and Variables

The first thing to internalize in Scala is the val/var split — immutable val is the default and var is the exception you reach for only when mutation is genuinely needed. This table also gathers the boundary types that sit at the top and bottom of Scala's unified hierarchy (Any, AnyRef, AnyVal, Unit, Nothing, Null) plus the Scala 3 conveniences — @main, top-level definitions, lazy val — that let you skip the ceremony older versions demanded.

KeywordExampleDescription
val
val x = 10
• Immutable value — cannot be reassigned after initialization
• preferred for most declarations
var
var y = 20
y = 25
• Mutable variable — can be reassigned
• use sparingly when mutation is necessary
lazy val
lazy val z = expensive()
Immutable value initialized only when first accessed — evaluation is deferred and cached
type annotation
val name: String = "Alice"
Explicit type declaration — usually optional due to type inference
top-level definition (Scala 3)
def helper(x: Int) = x + 1
@main def run() = println(helper(5))
In Scala 3, definitions can appear outside any class or object — no wrapper required
@main annotation (Scala 3)
@main def greet(name: String): Unit = println(s"Hello $name")
Marks a top-level method as program entry point — replaces object with main method

More in Programming Languages

  • Rust Cheat Sheet
  • String Processing and Text Manipulation Cheat Sheet
  • Arrays & Strings Cheat Sheet
  • Java Cheat Sheet
  • Object-Oriented Programming (OOP) Cheat Sheet
  • TOML Configuration Format Cheat Sheet
View all 31 topics in Programming Languages