The name Scala stands for Scalable language. Technically, Scala is a blend of object-oriented and functional programming concepts in a statically typed language.
This post explains sample SCALA program and how this is integrated to Hadoop.
- Sample Scala Program
- Sample Code to get Factorial
- What is Scala
- How Scala can be integrated
1. Simple Scala program:
var capital = Map("US" -> "Washington", "France" -> "Paris") capital += ("Japan" -> "Tokyo")
println(capital("France"))
How the above program works This program sets up a map from countries to their capitals, modifies the map by adding a new binding (“Japan” -> “Tokyo”), and prints the capital associated with the country France.
2. The sample code to get factorial
def factorial(x: BigInt): BigInt = if (x == 0) 1 else x * factorial(x - 1)
if you call factorial(30) you would get: 265252859812191058636308480000000
Scala is pure object oriented: Scala is an object-oriented language in pure form: every value is an object and every operation is a method call.
For example, when you say 1 + 2 in Scala, you are actually invoking a method named + defined in class Int. You can define methods with operator-like names that clients of your API can then use in operator notation.
Scala is also a functional language: In addition to being a pure object-oriented language, Scala is also a full blown functional language. Scala doesn’t require you to leap backwards off the Java platform to step forward from the Java language.
It allows you to add value to existing code—to build on what you already have—because it was designed for seamless interoperability with Java.
3. Scala is high-level language.
// this is Java boolean
nameHasUpperCase = false; for (int i = 0; i < name.length(); ++i)
{ if (Character.isUpperCase(name.charAt(i))) { nameHasUpperCase = true; break; } }
Whereas in Scala, you could write this:
val nameHasUpperCase = name.exists(_.isUpper)
The above example tells how simple you can write complex logic in one or two line. You can take QUIZ on Scala here.

4. How Scala and Hadoop both can be integrated
Scala is used in some of the Hadoop ecosystem components like Apache Spark, Apache Kafka, etc. So it would be really useful for someone to develop applications using Scala that uses Hadoop and the ecosystem projects. You can read a best example with Scala how to access Hadoop data.
Related Posts