Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .sc and .scala file?

I am learning scala and got know that we can save scala file using two extensions, that is my.sc and my.scala.

Here is the sample file which i created:

my.scala

object My {

  /** Our main function where the action happens */
  def main(args: Array[String]) {


    Logger.getLogger("org").setLevel(Level.ERROR)
    val sc = new SparkContext("local[*]", "my")
    val lines = sc.textFile("readme.tx")
    val results = lines.countByValue()

   }
}

my.sc

object My {

  val hello: String = "Hello World!"
  println(hello)
}

What is the difference between the two?

When to use sc file extension and when to use scala file extension?

like image 716
KayV Avatar asked Oct 19 '18 16:10

KayV


People also ask

What are .scala files?

A SCALA file is a source code file written in the Scala (Scalable language) programming language. Scala uses an object-oriented and functional approach with support of higher-order functions and nesting of function definitions.

How do I compile and run a scala program?

Press "control o" to save the file and then press enter. Press "control x" to exit the nano editor. To compile the code, type "scalac hello_world. scala" and press enter.


1 Answers

A .scala file is a regular Scala file, in order to be compiled and ran as a regular program. This is the most common scala file that you will use

An .sc file is a worksheet or a scratch, it is a file that will be evaluated as you save, the result for each expression is shown in a column to the right of your IDE. Worksheets are like a REPL session. It is useful to test some code in a quick way, just as you can do run the REPL

Edit

Awesome explanation here

What is the difference between scala classes, scripts and worksheets in Intellij-idea?

like image 147
SCouto Avatar answered Nov 12 '22 17:11

SCouto