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?
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 it, 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 with the REPL.
Edit
Awesome explanation here
What is the difference between scala classes, scripts and worksheets in Intellij-idea?