How to learn Scala ?

background
Reading Time: 2 minutes

In this article we will going to cover some introductory part about Scala programming language.

Scala Logo

Introduction to Scala

A contemporary multi-paradigm programming language called Scala was also created to describe common programming patterns in a clear, beautiful, and type-safe manner. Surprisingly It smoothly combines elements of functional and object-oriented languages.

Scala as Object Oriented Programming Language

Every value is an object in Scala, making it a wholly object-oriented language. Further, Classes and characteristics are used to describe the types and behaviour of things. In addition to providing a flexible mixin-based composition method as a clear alternative for multiple inheritance, classes can be extended through subclassing.

Scala as Functional Programming Language

Every function in Scala is a value, making it a functional language as well. However, it has a simple syntax for defining anonymous functions, along with support for higher-order functions, function nesting, and currying. Algebraic types, which are utilised in many functional languages, have features that it’s case classes and built-in pattern matching support offer. Functions that aren’t members of a class can be conveniently grouped together using singleton objects.

Similarly by way of a broad extension via extractor objects, Scala’s notion of pattern matching readily extends to the processing of XML data with the aid of right-ignoring sequence patterns. For comprehensions are helpful in constructing queries in this situation. It is perfect for creating applications like web services thanks to these capabilities.

Basic Operations in Scala

Defining a variable

Scala supports two ways of defining a variable.
1. var number: Int = 5
2. val number: Int = 7

var is used when you want to create a mutable variable, means you want to keep modifying it’s value while execution of the program.

val is used when you want to create a immutable variable, means you want to keep the value as it is throughout the execution of the program.

Defining a method

A method a is block of code which can have multiple parameters and return a value as a result.

def additionOfTwoNumbers(x: Int, y: Int): Int = x + y

Defining a class

class Welcome(name: String) {
def greet(name: String): String = s”Welcome
$name, How are you ?”
}

Reference

For more similar article visit: https://blog.knoldus.com/category/scala/
In addition visit click here to visit official documentation

Written by 

Pallav is working as Software Consultant at Knoldus Inc. He is a technology enthusiast and a keen learner with more than 1.5 years of experience. He works as a Quality Catalyst in the organization. He has a good understanding of programming languages like Java and Scala. He likes to listen to songs and playing table tennis.