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 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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With