Useful Scala commands

Go to scala shell

scala
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

Exit scala shell

Use exit of CTRL-D

scala> exit
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
[raj@Rajkumars-MacBook-Pro ~/gitws/scalaexamples]

Execute a Scala script

cat ./o990_others/a11_Demo.scala

println("This is a demo of script")

scala ./o990_others/a11_Demo.scala
This is a demo of script

Note : A scala script do not need the code to be enclosed in class / object whereas a Scala Application does need a class / object to enclose the code

Compile Scala Application

cat src/main/scala/e11_Classes/a11_101/a11_Basic.scala

package e11_Classes.a11_101

object a11_Basic {
  def main(args: Array[String]) {
    println("This is an Application")
  }

scalac src/main/scala/e11_Classes/a11_101/a11_Basic.scala

ls -l e11_Classes/a11_101/
total 16
-rw-r--r--  1 raj  staff  645 Apr 29 20:17 a11_Basic$.class
-rw-r--r--  1 raj  staff  659 Apr 29 20:17 a11_Basic.class

Execute a scala Application

scala -cp . e11_Classes.a11_101.a11_Basic
This is an Application

Here -cp option represents the CLASSPATH


No comments:

Post a Comment