Register Login

Scala

Scala is an amalgamation of object-orientation programming language and functional programming language which runs on the JVM (Java Virtual Machine). Scala was created by Martin Odersky and promoted by Typesafe Company. Therefore we need to use some tools of Typesafe in order to learn Scala. Scala was officially released for Java platform in early 2004 and for .Net framework in June 2004.

There are lots of people who haven’t heard about Scala, they know Java and other languages but not Scala. Scala is very important, very fast and very efficient. Also, Scala is very important in the World of Big Data.

Scalability of Scala Language

Scala stands for scalable language. Does this mean that other languages are not scalable? Java is scalable, python is scalable, all this languages are scalable, but there is a limit to the scalability. When it comes to java it is scalable to an extent, similarly python is scalable to an extent. But scala is a programming language which was built scalability, Actually the main motto of building scala was scalability, that’s why scala stands for scalable language. Scalability is one of the important features of scala.

What are the Prerequisites to Learn Scala?

There are certain prerequisites which needed to be fulfilled before starting up with Scala.

These prerequisites can be divided into two categories:

  • In terms of knowledge
  • In terms of software

Knowledge Prerequisite

So to learn Scala you must have knowledge of Java (at least at beginner level if not expert level) such as

  • What are variables
  • Loops in Java
  • Arrays in Java
  • How do you create an object?
  • Using collection and thread in Java etc.

At least if you know the basics of the things mentioned above then you can learn Scala easily. But If you don’t know these things then please learn basic understanding of how Java works and then you can jump into Scala. So that is the knowledge prerequisites.

Software Prerequisites

So before installing Scala your machine needs java and also you need to install some software listed below:

  • First of all, you need to install JDK in your machine because it will make sure that you have JDK and JVM on your machine, an updated version of JVM.
  • Second, you need Eclipse because what we will be doing is we will be installing a plugin of Scala in eclipse plugin of Scala in eclipse.

Note: You can use Scala on the command line, you can use Scala inside NetBeans, intelliJ or you can download scala itself instead of using Scala on Eclipse.

Advantage of Scala

  • Scala is faster than Ruby, Python and node.js so scala is faster than all these languages. Now people are going for Python and Nodejs but trust me these languages are not faster than scala.
  • And one more reason to learn scala, even If you are a java programmer and you want to learn scala, the reason is that if you are java programmer and you want to spend more time with family and friends then you must learn scala because if you want to do a particular task in java in twenty lines, you can do the same stuff in scala in 5-6 lines. So you don’t have to waste too much time in writing code.
  • Another advantage when you write a java application, you have lots of lines of code, so if you have one bug, it is very difficult to detect where that bug is. And scala is well you know, the core in scala looks beautiful. So even if you have a bug then you can remove it. It is that efficient.

Big Data and Scala

Now what next? The world is changing right? So everywhere we have this big data, we are generating a huge amount of data, so we have this concept of big data. And to work with big data we need a framework called Hadoop. We have another framework, the latest for big data, which is called Spark. For working with Hadoop we can opt to use Java or Scala but if we work with spark, the only language we can work with is Scala.

Therefore in case if you are going for big data on Spark framework, then you need to learn Scala. If you are going for certification for Hadoop Spark then it is very important to know Scala programming language.

Boiler Plate Codes in Scala

The next important thing is, you know, there is always a debate about which is the best programming language. Some like Python and some java, people who love python say that in Python if you want to print "“hello world", you only have to write one line and to do the same thing in java, you have to write six lines of code. You have to write a class, a main method, you have to write system.out.println and then you can say hello world.

Its bit odd, in Jave we have, it is a structured language. Yes there is a boiler plate code in java because it is a structured language. And it has certain boiler plate codes. Now there are lots of programmers in java who thinks java should be modified as we need less boilerplate codes. So they tried to modify java and they came out with scala. So we cannot say that there is much difference between java and scala. Scala is java with some changes. So there is no boiler plate code is scala, so if you want to print something, you directly write a line and print it.

You don’t have to write any boiler plate code in Scala. When it comes to boiler plate code, it simply means those lines which are not important. For example – if you want to print “Hello world” in java, the most important line is ‘system.out.println’ but we have to mention class the main method that is boiler plate code.

Concurrency in Scala

Java supports concurrency, now why we need concurrency is because we are living in an age of octa-core CPUs. In our CPUs, initially we had one core, then we had two core which is dual core machines, then we got quad-core machines and now we have octa-core CPUs. So when you have octa-core CPUs means that there are multiple cores, so we have to make sure that we write a software, it should be efficient enough to utilize all the available cores. And scala provides you that feature. Even if you don’t know it, Scala will do it automatically for you. So scala provides concurrency.

So we have talked about Scala being scalable language, it works on big data, it doesn’t have boiler plate codes and it is concurrent. And what else? In fact there is a quote from Alan J Palace “ A language that doesn’t change the way you think about programming is not worth learning.” So that means after learning scala, it will change the way you think about programming. No its not about procedures, its not about objects now, its more about functions. Because Scala is functional programming. In scala we only have to focus on functions. Scala is functional programming.

Now it may happen that you don’t want to make your career in Big Data, you don’t want to do any other stuff. But even if you learn scala, it will change the way you write your java codes.

    Java and Scala 

    Scala is better than java you can say that scala is an upgraded version of java. Now the question arises? Does that mean this is the end of java? And the answer is No. Java will forever be there, but there are some requirements where scala is better than Java. For example- when twitter was made in 2009, they used Ruby language, but later on because of lots of tweets, this big data concept, So it was very difficult for the twitter to manage all this data using Ruby language. So what they did was remove Ruby from the backend and now they are using Java and Scala on the backend, that means they are using both and they work together. It’s because Java runs on JVM and Scala also runs on JVM. That means you can write one application which is a java based application, and you are using Scala code there. And you can write a Scala application on which you are using java code. That means a java project support scala code and a Scala project supports java code.

    In Scala you can use all the java libraries. So if you know java then you can learn scala in one month. But if you don’t know java then scala is a bit difficult. I am not saying it is impossible to learn scala but it will be difficult to understand. Scala and java work together. Scala also runs on JVM, and nobody loves java as everyone loves JVM, therefore, we can Scala is powerful than Java.

    Companies using Scala

    Below are the names of some famous companies using Scala language:

    • LinkedIn
    • Twitter
    • Foursquare
    • Netflix
    • Tumblr
    • Sony etc.


    Tutorials

    • Define Method and Function in ScalaDefine Method and Function in Scala
      How to create methods in Scala?Enter a keyword ‘def’ to define the function and then a function called show(). You need to use the ‘=’ operator to define a function. def show() ...

    • Scala Environment SetupScala Environment Setup
      How to Setup Scala Environment?1.Scala works on JVM and eclipse supports JVM so we can run Scala on eclipse.2.Go to the official website of Scala, you will find that 'The most popular way to get Scala ...

    • Code Example- Getting Started with ScalaCode Example- Getting Started with Scala
       First Scala Program 'Hello World' 1. In Java, if you want to print 'Hello World' then you have to write the following lines, which is around 5-6 lines of code. class Demo ...

    • Lambada expression and list of value in ScalaLambada expression and list of value in Scala
      How to use function literals in Scala? To create a list in Java, write the following lines of code and import the package. public static void main (String[] orgs) { List<Integer> num ...

    • Scala Type Hierarchy OverviewScala Type Hierarchy Overview
      Scala type hierarchy vs Java type hierarchyIn Scala, you can mention the method name without a dot operator.When entering a list of numbers, it will return you a list of [int]If you add a boolean valu ...

    • Define Complex Objects In ScalaDefine Complex Objects In Scala
      List of Complex Objects In ScalaTo create a list of complex objects in Scala, follow the steps listed below. In this example, we will be creating a list of students. To create a list of students, you ...

    • Scala Classes and ObjectsScala Classes and Objects
      How to create Classes and Objects in Scala? Create a Class in Scala 1) You can create a Class in Scala using the command 'case class classname()'. So for example for creating a clas ...

    • Reverse a List in ScalaReverse a List in Scala
      How to reverse a list in Scala 1) Create a list for ex. 4,7,2,3. Use var nums = List(4,7,2,3) to create the list. 2) To reverse this list type 'nums.reverse and choose rever ...

    ×