- Scala is statically type like Java but with Type Inferencing support. Which means that the scala compiler analyzes the code deeply to determine what type a particular value is.
- In Scala its not required to use semicolons to terminate a statement if the termination is obvious by line ending. If there are more than one statements on the single line then they have to be separated by using semicolon.
- Scala doesnot require the file containing a class definition to mirror the name of the class.
- In Scala there’s no use of static all together. This is replaced by use of singleton object. Singleton objects are declared by using the keyword “object” and not “class”.
- In Scala, arrays are instances of Array class and uses square brackets () instead of angle brackets (<>) to indicate parameterized types.
- In Scala the variable declaration is: “name: type”
- Scala uses keyword “Unit” to represent functions which return “non-value” value.
- In Scala the syntax for method declaration is different. It uses the “=” before the method body preceeded by the identifier/name of the method along with the parameter list and return type. Functions are treated like variables and constants.
- Scala supports the use of closures, Annonymous functions- Which makes longer code simpler and shorter.
These were few things i have noted. There are lot more differences. If u know any please add it as a comment. Will upadate my post accordingly.
1 thought on “How’s Scala different from Java?”
Very nice post about scala.