Introduction to Scala
David Venturi
Curriculum Manager, DataCamp
$ scala
Welcome to Scala 2.12.7.
Type in expressions for evaluation. Or try :help.
scala> 2 + 3
res0: Int = 5
scala
command executes a script by wrapping it in a template and then compiling and executing the resulting programIf we put this code into a file named game.scala
:
// Start game
println("Let's play Twenty-One!")
Then run:
$ scala game.scala
Let's play Twenty-One!
Interpreter: a program that directly executes instructions written in a programming language, without requiring them previously to have been compiled into machine code.
Compiler: a program that translates source code from a high-level programming language to a lower level language (e.g., machine code) to create an executable program.
If we put this code into a file named Game.scala
:
object Game extends App {
println("Let's play Twenty-One!")
}
First, compile with scalac
:
$ scalac Game.scala
Second, run with scala
:
$ scala Game
If we put this code into a file named Game.scala
:
object Game extends App {
println("Let's play Twenty-One!")
}
First, compile with scalac
:
$ scalac Game.scala
Second, run with scala
:
$ scala Game
Let's play Twenty-One!
$$
There are two main ways people prefer to work in Scala:
IntelliJ IDEA
sbt
"simple build tool"
Compiles, runs, and tests Scala applications
Introduction to Scala