Scala는 JVM(Java Virtual Machine)에서 실행되는 함수형 및 객체지향 프로그래밍 언어이다. Java와의 높은 호환성을 가지며, 간결하고 강력한 표현력을 제공하는 것이 특징이다. 대표적인 활용 사례로는 Apache Spark 및 분산 데이터 처리, 웹 애플리케이션 개발 등이 있다.
wget https://downloads.lightbend.com/scala/2.13.12/scala-2.13.12.tgz
tar -xvzf scala-2.13.12.tgz
sudo mv scala-2.13.12 /usr/local/scala
echo 'export PATH=/usr/local/scala/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
vagrant@slave2:~/hello-world-template$ scala -version
Scala code runner version 2.13.12 -- Copyright 2002-2023, LAMP/EPFL and Lightbend, Inc.
소스 Hello.scala 생성
object TestHello {
def add(x: Int, y: Int): Int = x + y
def main(args: Array[String]): Unit = {
assert(add(2, 3) == 5)
assert(add(0, 0) == 0)
println("All tests passed!")
}
}
실행
vagrant@slave2:~/helloworld$ scala hello.scala
Hello, World!
테스트 소스 TestHello.scala 생성
vagrant@slave2:~/helloworld$ scala TestHello.scala
All tests passed!
REPL (Read-Eval-Print Loop)이란 코드를 입력하면 즉시 실행하고 결과를 보여주는 인터페이스이다.
scala> val x = 10
x: Int = 10
scala> x * 2
res0: Int = 20