Home > Scala > How’s Scala different from Java?

How’s Scala different from Java?

  • 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.

Advertisements
Categories: Scala Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: