Scala -
High level language for JVM. Its Object oriented + functional programming. Java is catching up by introducing Lambda expressions in Java8.
It has type inferred feature and can be use to call or get called from Java code.
Scala is simple to use. most often while working you declare variables and define functions which operate on those variables. Scala has very simple in both the aspects and most of the type you dont have to care about the type of the variable while using Scala
Declaring Variable in Scala
// declaring a variable as intvar x: Int = 7
// declaring a variable. Scala will infer the type at runtime
var x = 7
// declaring a read/only or final variable
val x = 7
Function Definition is Scala is more like C++/script language type
Syntax -
def functionname( param: type) : return type = body of the function
so defining square function for int as below
def square(x: Int) : Int = x*x
the other way if you have multi-line function
def square(x: Int) : Int = {
x*x
}
You can write a functions as
(x: Int) => x*x
all the three syntax will give same result.
You detailed overview I suggest to follow the link - http://www.scala-lang.org/
No comments:
Post a Comment