Scala
Scala is a general purpose programming language.
Supports both object oriented and functional programming style
Martin Odersky and his team started in 2001, publicly released in Jan, 2004 and few months later on .NET platform.
Everything in Scala is Object, doesn't have primitives, why?
Doesn't allow any mutable state.
Framework in Scala
- Play - for web development
- Akka - Actors based framework
- Scalding - For Map Reduce
- Spark - in memory processing
Why Scala?
Developers want more flexible language to improve their productivity, which leads to languages like Python, ruby etc.
Scala - Static Language
Scala REPL : Read - Evaluate - Print - Loop
Scala Shell, even though it appears as interpreter, all typed code is converted to Byte code and executed.
2 kinds of variable:
- immutable (val) (Read only)
- mutable (var) (RW)
lazy values are very useful for delaying costly initialization instruction. Lazy values don't give error on initialization.
lazy val file=scala.io.Source.fromFile("vikas").mkString
From A Java Developer's POV:
HelloWorld
object HelloWorld { def main (args: Array[String]) { println ("Hello World") } }
Save this code and let's say the file name is "HelloWorld.scala"
To compile
scalac HelloWorld.scala
To Run the program
scala HelloWorld
or
scala -classpath . HelloWorld
output:
Hello World