Introduction to SCALA

Why SCALA?

You might get surprised why I am writing a blog about SCALA. Writing blog on DotNet and Python and suddenly jump to SCALA. The reason is that I get a project, which I have to complete in SCALA. As I start exploring the language I find out its quite interesting. Therefore I thought to write a series of posts to share what I am going to learn about SCALA.

What is SCALA

SCALA is an abbreviation of  the term “Scalable Language”. It  is a high performance functional and object oriented language on the Java Virtual Machine (JVM) platform.  As SCALA requires Java runtime, Java and SCALA classes can be freely mixed. SCALA is a pure Object Oriented language and it supports all OOP features, support design patterns and even you can add new operations to existing classes either they are from SCALA or JAVA. SCALA is also known as functional language and it has all the ingredients including first-class functions, a library with efficient immutable data structures, and a general preference of immutability over mutation. To get more information about SCALA and its documentation you can explore its website.

Installing SCALA

SCALA 2.11 requires at least Java 6 to run the code. But I suggest to use the latest Java version, at present its Java 8. You can download the latest JDK from the Oracle site. Once you install the JDK, download the SCALA latest version from the SCALA website (which is 2.11.7).  I will use SCALA IDE to write down the program, but in the start I will use command promote to execute the code and see the output.

Writing HelloWorld

Once you install the JDK 8 and SCALA on the machine, open the command promote and type Scala. If everything is properly installed you will see the Welcome to Scala message as shown in the figure below, the SCALA command provides REPL (Read, Eval, Print, Loop)

Scala-Img1

To print a string simply type println(“Hello World”)  on the Scala command window (REPL) and you will see the output.

Scala-Img2

Congratulation, you write your first program in SCALA. SCALA has another advantage over Java, that you need less line of code in SCALA to perform same operation in JAVA.  To do calculation is even simpler just type 5 * 5  in REPL and you will see that instead of print this time REPL return the value in a variable. The variables “res” are constant and are numbered sequentially. We can use these variables. Our first result is return in res1, lets multiple it with 2  2 * res1 The output will be store in variable 2 (res2).

Scala-Img3

To quite from the SCALA command promote just type :q. I hope you find this post interesting and get interest in learning SCALA. SCALA is used by LinkedIn, Twitter and Netflix and many other big names. And its getting popular day by day, and the demand for SCALA is increasing. I think its a good time to invest in SCALA.

Leave a Reply