Introduction to Scala
Scala runs on the JVM, uses every Java library, and adds powerful functional programming with concise syntax.
On this page · 5 min · Beginner
On this page
- In simple words
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 30, 2026
Related tutorials
In simple words#
If Java is a reliable family car, Scala is the same engine (the JVM) in a sports body: shorter code, more features, and it still drives on every road Java does.
- JVM
- Same runtime as Java — Scala compiles to bytecode.
- Functional programming
- Building programs from pure functions and immutable data.
- Scala 3
- Current major version with cleaner syntax.
Learning objectives#
- Explain what Scala is
- Know where Scala is used
- Write a Scala 3 main method
- Compare Scala and Java briefly
Explanation#
Scala = “scalable language”: small scripts to large distributed systems.
It is fully object-oriented (every value is an object) and functional (functions are values; immutability is the default style).
Used in data engineering (Apache Spark, Kafka tooling), back ends (Play, http4s, ZIO, Akka/Pekko) and at companies like LinkedIn, Netflix and Twitter/X.
Scala 3 uses @main methods, optional braces with indentation, enums, given/using and extension methods.
Code example: Hello Scala 3#
@main def hello(name: String = "Techie Babaji"): Unit =
val greeting = s"Namaste from Scala, $name!"
println(greeting)
val squares = (1 to 5).map(n => n * n)
println(s"Squares: ${squares.mkString(", ")}")
// Run: scala run Hello.scala
Namaste from Scala, Techie Babaji! Squares: 1, 4, 9, 16, 25
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- @main marks the entry point.
- val declares an immutable value.
- s"…" interpolates variables.
- map transforms a range in one line.
Real-world use case#
Data engineers write Spark jobs in Scala to process terabytes of logs and transactions.
Common mistakes#
Mutable vars and loops everywhere miss Scala’s strengths. Prefer val and collection methods.
Syntax differs (implicit vs given, object Main extends App vs @main). Check the version.
Best practices#
- Learn Scala 3 syntax
- Prefer immutable values
- Use the REPL to experiment
- Learn Java basics first if new to the JVM
Remember this#
Scala = OOP + FP on the JVM.
@main starts a program.
val by default.
Practice exercise#
Your task: Print the sum of numbers from 1 to 100.
Show solution
println((1 to 100).sum) // 5050
Mini quiz#
Which platform does Scala mainly run on?
Want more? Practise all Scala MCQs · Scala interview questions
My notes#
Saved in this browser.