Reason to learn scala
Posted on by Sumit KumarScala is an acronym for Scalable Language.
Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise ,elegant and type-safe way.
multi-paradigm programming means it supports Object oriented programming as well as fuctional programming.
So scala is a scalable programming language for component software with the focus on pattern like abstraction ,composition , decomposition and not primitive type.
Scala is written by Martine Odersky at EPFL.
Below are the feature of Scala.
1)Scala is Statically Typed:- It will catch type error at compile time. scala use type inference very well.
2)Scala runs on JVM and its fully inter-operable with JAVA.
3)Scala is a pure object-oriented language in the sense that every value is an object.
4)Scala is also a functional language in the sense that every function is a value
5)Dynamic feature.
6)Less coding:-
Scala avoid to write verbose and boilerplate syntax. Scala compiler(scalac)
can generate toString(), equals(), hasCode() and other things for programmer.
Take a look on below java class.
public class Employee { private final String name; private final double salary; public Star(String name, double salary) { this.name = name; this.salary = salary; } @Override public int hashCode() { int hash = 7; hash = 23 * hash + Objects.hashCode(this.name); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Check123 other = (Check123) obj; if (!Objects.equals(this.name, other.name)) { return false; } if (Double.doubleToLongBits(this.salary) != Double.doubleToLongBits(other.salary)) { return false; } return true; } @Override public String toString() { return "Check123{" + "name=" + name + ", Salary=" + salary + '}'; } }
Now see the one line code for the same in scala.
case class Employee(name: String, salary: double)
This is also one of the main reason, programmer preferring scala language over JAVA.
So we can use as replacement of java. We can use java and scala code together.We can use existing Java libraries.Along with that we can use same build tools that we are using in java(Ant,maven,etc)
Apart from all the above feature and reason to learn scala , my reason to learning scala is obviously to learn spark. As spark is written in scala.
We will learn spark also after learning scala.
Resource:-
Leave a Reply