scalabeginner
Scala Hello World Application
Create a basic Scala application with main method, string interpolation, and val/var basics.
scalaPress ⌘/Ctrl + Shift + C to copy
// Scala 3 syntax
@main def hello(): Unit =
val name = "World"
println(s"Hello, $name!")
// Val (immutable) vs Var (mutable)
val immutable = 42 // cannot be reassigned
var mutable = 10 // can be reassigned
mutable = 20
// String interpolation
val x = 10
val y = 20
println(s"$x + $y = ${x + y}")
// f-interpolator for formatting
val pi = 3.14159
println(f"Pi is $pi%.2f")
// Raw strings
val path = raw"C:\Users\name\docs"
println(path)
// Multi-line strings
val json = s"""|
|{
| "name": "$name",
| "value": $x
|}""".stripMargin
println(json)Use Cases
- Getting started with Scala
- Understanding val vs var immutability
- String formatting and interpolation
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
scalabeginner
Pattern Matching Fundamentals
Use Scala pattern matching with guards, type patterns, tuple patterns, and nested extractors.
Best for: Control flow with pattern matching
#scala#pattern-matching
scalabeginner
Tuples and Product Types
Work with Scala 3 tuples: named tuples, tuple operations, conversions, and generic programming.
Best for: Returning multiple values from functions
#scala#tuples
scalabeginner
List Operations Basics
Essential list operations: head, tail, cons, zip, groupBy, sliding, partition, and span.
Best for: Data processing and transformation
#scala#list
scalabeginner
Case Classes and Objects
Define immutable data with case classes: copy, equality, destructuring, and companion objects.
Best for: Domain modeling with immutable data
#scala#case-class