Click on a topic to expand and learn in detail.
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, Scala!")
}
}
Scala combines functional and object-oriented programming paradigms.
var name: String = "Alice" // mutable
val age: Int = 25 // immutable
val pi: Double = 3.14
Use var for changeable values, val for constants.
def add(a: Int, b: Int): Int = {
a + b
}
println(add(5,3))
Functions are reusable blocks of code.
class Person(val name: String, var age: Int){
def greet(): Unit = println(s"Hello $name")
}
val p = new Person("Alice", 25)
p.greet()
Scala supports classes, objects, and OOP principles.
val numbers = List(1,2,3,4,5)
val squares = numbers.map(x => x*x)
println(squares)