Scala

Introduction

Why Scala?

  1. Blend of Functional and object oriented language(provides Best of both)
  2. Use of immutable Data structures (value of variable intact so less bug prone)
  3. Rich Collection library
    1. Library is divided in mutable and immutable Data Structure.
    2. Collection which can be lazy or can be eager in its evaluation.
    3. Provides collection that can run in parallel that speed up processing.
  4. Better concurrency support
    1. Leverage multi-core machine capability without needing us to do more
    2. In Java we have to do a lot of low level task of handling the threads e.g
      1. Acquiring and releasing the lock (synchronised/static synchronised),this is simplified in Scala.
    3. concurrency is first class citizen in Scala

Scala frameworks are Play, Lift whereas Java frameworks are Spring, Grails, and many more.

ParameterScalaJava
CompactnessMore compact and conciseComparatively larger chunks of code
Designed forIt is designed and developed to be both object and functional oriented language.
It supports a wide variety of functional programming features such as concurrency and Immutability.
Originally developed as an object-oriented language and started supporting functional programming features in recent days. It is not as strong as a functional programming language.
Concurrency modelUses actor model for supporting modern concurrencyIt uses the conventional thread-based model for concurrency.
Supported frameworksSupports frameworks – Play, LiftSupports Spring, Grails, much more
Lazy evaluation supportSupports lazy evaluationDoes not support lazy evaluation
Static membersNo static membersContains static members
Operator overloadingSupports operator overloadingDoes not support operator overloading
Compilation processCompilation of source code is comparatively slowCompilation of source code is faster than Scala
InterfacesTraits – act like Java 8 interfacesJava 8 interfaces try to bridge the gap between classes and interfaces
URL rewritingRewriting is neededRewriting is not required
Bug-free codesNo assurance about the bug-free codesComplete assurance of lesser defects
Support for backward compatibilityScala does not support backward compatibilityJava supports backward compatibility
Support for Multiple inheritancesSupports multiple inheritances using classes but not by abstract classesDoes not support multiple inheritances using classes, but by interfaces
Code styleCode is written in a compact form.Code is written in long-form.
Static keywordScala does not contain the static keyword.Java contains the static keyword.
TreatsAny method or function present in Scala is
they are treated like they are variable.
Java treats functions as an object.
Type of variablesScala variables are by default immutable type.Java variables are by default mutable type.
Object orientationScala treats everything as an instance of the class and it is more object-oriented language as compare to Java.Java does not support operator overloading.
Calling methodIn Scala, all the operations on entities performed using method calls.Operators are treated differently and is
not done using the call method.
ReadabilityScala is less readable because of its nested code.Java is more readable.
Compiling processCompiling the process of source code into byte code is very slow.Compiling the process of source code into byte code is fast.

Installation

  1. sudo apt-get install scala
  2. Verification
    1. scala -version
  3. IDE
    1. easy integration with intellij – install and
      1. add plugin scala

Scala Versions

  1. Latest V3
  2. before this was version 2

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment