Open In App

Introduction to Scala

Scala is a general-purpose, high-level, multi-paradigm programming language. It is a pure object-oriented programming language which also provides the support to the functional programming approach. There is no concept of primitive data as everything is an object in Scala. It is designed to express the general programming patterns in a refined, succinct, and type-safe way. Scala programs can convert to bytecodes and can run on the JVM(Java Virtual Machine). Scala stands for Scalable language. It also provides the Javascript runtimes. Scala is highly influenced by Java and some other programming languages like Lisp, Haskell, Pizza, etc.

Evolution of Scala:
Scala was designed by the Martin Odersky, professor of programming methods at École Polytechnique Fédérale de Lausanne (EPFL) in Switzerland and a German computer scientist. Martin Odersky is also the co-creator of javac (Java Compiler), Generic Java, and EPFL’s Funnel programming language. He started to design the Scala in 2001. Scala was first released publicly in 2004 on the Java platform as its first version. In June 2004, Scala was modified for the .Net Framework. Soon it was followed by second version i.e. (v2.0) in 2006. At JavaOne conference in 2012, Scala was awarded as the winner of the ScriptBowl contest. From June 2012, Scala doesn’t provide any support for .Net Framework. The latest version of scala is 2.12.6 which released on 27-Apr-2018.



Why Scala?

Scala has many reasons for being popular among programmers. Few of the reasons are :  

Note: People always thinks that Scala is a extension of Java. But it is not true. It is just completely interoperable with Java. Scala programs get converted into .class file which contains Java Byte Code after the successful compilation and then can run on JVM(Java Virtual Machine). 



Beginning with Scala Programming

Finding a Compiler: There are various online IDEs such as GeeksforGeeks IDE, Scala Fiddle IDE, etc. which can be used to run Scala programs without installing.

Programming in Scala: Since the Scala is a lot similar to other widely used languages syntactically, it is easier to code and learn in Scala. Programs can be written in Scala in any of the widely used text editors like Notepad++, gedit, etc. or on any of the text-editors. After writing the program, save the file with the extension .sc or .scala

For Windows & Linux: Before installing the Scala on Windows or Linux, you must have Java Development Kit(JDK) 1.8 or greater installed on your system. Because Scala always runs on Java 1.8 or above. 
In this article, we will discuss how to run the Scala programs on online IDE’s. 

Example : A simple program to print Hello Geeks! using object-oriented approach.




// Scala program to print Hello, Geeks!
// by using object-oriented approach
 
// creating object
object Geeks {
 
// Main method
def main(args: Array[String])
{
     
    // prints Hello, Geeks!
    println("Hello, Geeks!")
}
}

Output: 

Hello, Geeks!

Comments: Comments are used for explaining the code and are used in a similar manner as in Java or C or C++. Compilers ignore the comment entries and do not execute them. Comments can be of a single line or multiple lines. 

// Single line comment
/* Multi-line comments
   syntax */

object Geeks: object is the keyword which is used to create the objects. Here “Geeks” is the name of the object.
def main(args: Array[String]): def is the keyword in Scala which is used to define the function and “main” is the name of Main Method. args: Array[String] are used for the command line arguments.
println(“Hello, Geeks!”): println is a method in Scala which is used to display the string on console.

Note: There is also functional approach that can be used in Scala programs. Some Online IDE doesn’t provide support for it. We will discuss it in upcoming articles.

Features of Scala

There are many features which makes it different from other languages. 

Advantages:  

Disadvantages:  

Applications: 

 


Article Tags :