I'm using Intellij-idea for scala programming (with sbt plugin).
I want to know what is the difference between scala classes, scala scripts and scala worksheets. When we use each of them?
This will be very nice if you can explain it by a simple example.
Thanks
Scala Worksheet
It's the same as Scala Interpreter (REPL) but runs inside IntelliJ. Where you may easily and quickly evaluate some expressions. Check IntelliJ confluence page for more information.
Scala Script
If you don't want write script on Bash you can do it with Scala. It's just sequence of Scala statements.
Example:
Running it:
To getting started pick up this guide.
Classes & Object
Short answer for Scala classes it's similar to POJO and Scala Objects it's a Java Singleton class.
You have different ways of running scala code:
First create a Program with your classes, this is as in java, I use object because it works well without instantianing, like static, just compile with the SBT and run it you can also use the scala Interpreter REPL
We can use this object in the REPL
compiling and running it using activator/SBT
The second is that if we add the scala code as a script or file Hello.scala, You can save your scala code in the file with .scala extension (basically with any file extension but prefered .scala extension) and to run, provide file name with extension as parameter to scala interpreter
if we call the scala interpreter this file is executed, you do not need to instanciate objects or clases, just executing like a shell script, you can also execute directlyy from Intellij, but I use the console with scala installed on the system
And finally the worksheet is the most powerfull, I recommend this for increasing your prodductivity at work bacause it is easy to test things is like the REPL, ant it evluates the scala exprssions and shows you back the result
Following is excerpt from official github repo wiki about the scala worksheet
A worksheet is a Scala file that is evaluated on save, and the result of each expression is shown in a column to the right of your program. Worksheets are like a REPL session on steroids, and enjoy 1st class editor support: completion, hyperlinking, interactive errors-as-you-type, auto-format, etc.
the result
then a capture that shows you working with classe the work sheet and the console for scriptsin the Intellij