Scala

What is Scala? the first time that I heard Scala, I thought that maybe is a character from a Video Game or a new music band.

But the truth goes further, Scala is a programming language, most programmers say that is Java without semicolons, and is true but also Scala simplifies Java removing all the boilerplate of Java.

So if you come from Java or have a Java background it will be easy to learn it. But if you don’t come from Java don’t worry because you can learn Scala syntax as if it were a new programming language.

The page of Scala says: The name Scala comes from Scalable Language. Scala scales not only with hardware resources and load requirements but also with the level of the programmer’s skill. If you choose, Scala rewards you with expressive additional features, which when compared to Java, boost developer productivity and readability of code.

That means that Scala can adapt to different situations like the hardware and load requirements. Additionally, Scala can adapt to the skill level of the programmer, making it usable by both novice and expert programmers.

If you choose to use Scala, this language rewards you with additional features that allow you to write more expressive code, resulting in greater productivity and easier readability of code. This means that compared to Java, Scala allows you to write code in a more efficient and readable way.

Example of Scala application

The next code is an example of a Scala code:

/**
* Objeto that add two numbers and show the result in the console.
*/
object AddTwoNumbers {
/**
* Principal method that is executed when the application Starts.
* @param args CLI Arguments (not are used on this example).
*/
def main(args: Array[String]): Unit = {
// Define two nums to add
val num1 = 10
val num2 = 5
// add the two numbers and stored into a new variable called sum
val sum = num1 + num2
// print the result in the console
println(s"The sum of $num1 and $num2 is $sum")
}
}

The above code defines an object called AddTwoNumbers that has a main method that takes an array of arguments of type String. Inside the main method, two variables num1 and num2 are defined with values of 10 and 5 respectively. Then, num1 and num2 are added together and the result is saved in the variable sum. Finally, the result is printed using the println function.

You can download the code from our repository Learning_Scala to test for yourself.

What do you think of Scala? let us know below in the comments.

Happy Learning!!

Leave a comment