Introduction to Scala

These days majority of the hadoop applications/tools are being built in Scala Programming language than in Java. So it is good for hadoop developers/Java programmers to learn Scala as well. This post is just an introduction to Scala.

What’s Scala?

Scala is a hybrid functional and object-oriented programming language which runs on JVM (Java Virtual Machine). The name is an acronym for Scalable Language. It is designed for concurrency, expressiveness, and scalability.

Why Scala?

  • Concise and Light Weight Syntax.
  • Multi-paradigm Language. It supports both Object-oriented constructs and Functional programming constructs as well.
  • Language for the Java Virtual Machine
  • Purely object-oriented. Inter-operates very well with famous programming language Java
  • Simplifies the concurrency programming without the worries of data contention between threads and no dealing with locks is needed
  • We can retire the synchronized keyword from our programming
  • Very concise, for example 100 lines of Java Code can be achieved within 10-20 lines of code in Scala some times
  • Other powerful capabilities of Scala are sensible static typing, closures, immutable collections, and elegant pattern matching
  • Only prominent strongly typed language that provides functional style and great concurrency support

Scala Cons

  • Some times Scala’s conciseness make it hard to understand the code
  • The syntax is not going to be easy for the beginners

History of Scala

Scala is created by Martin Odersky (the father of javac ), influenced by Java, Ruby, Smalltalk, ML, Haskell, and Erlang and was first released in 2003. Its being used in the busiest websites like Twitter, LinkedIn, Tumblr, Netflix, and etc.

Programming Notes

  • There are no primitive types in Scala, Everything is an object in Scala. For example, 2.toString(), will call toString ( ) method on an instance of Int.
  • Every variable is an object, and every “operator” is a method.
  • Scala compiles down to byte-code.
  • We can extend Java classes from Scala classes, and vice versa. We can also use Java classes in Scala and Scala classes in Java
  • Semicolons at the end of each code line are optional in Scala.
  • Depending on the context, the dot operator ( . ) and the parentheses are optional in Scala. So, instead of writing s1.equals(s2); , we can write s1 equals s2
  • Scala doesn’t support static methods unlike Java, but the same can be achieved through singleton objects as shown below.

This can be called as HelloWorld.welcome() which is similar to static method call.

  • Scala is a functional language also, i.e. we can assign functions to variables, and pass functions to methods and functions as arguments and methods and functions can return them also.In the next topic we will discuss about installation of Scala on Ubuntu.

Profile photo of Siva

About Siva

Senior Hadoop developer with 4 years of experience in designing and architecture solutions for the Big Data domain and has been involved with several complex engagements. Technical strengths include Hadoop, YARN, Mapreduce, Hive, Sqoop, Flume, Pig, HBase, Phoenix, Oozie, Falcon, Kafka, Storm, Spark, MySQL and Java.

Leave a comment

Your email address will not be published. Required fields are marked *