I. Introduction to Scala

1.1 concept

Scalable Language, as Scala stands for “Scalable Language,” is so named because it is designed to grow with the needs of its users. Scala is a statically typed programming language that combines object-oriented and functional programming concepts. It runs on the standard Java platform and works seamlessly with all Java class libraries.

1.2 the characteristics of

1. Scala is object-oriented

Scala is an object-oriented language where every value is an object and every method is a call. For example, if you do 1+2, Scala is actually calling the method named + defined in the Int class.

Scala is functional

Scala is not only a pure object-oriented language, it is also a fully functional programming language. Functional programming is guided by two core concepts:

  • The function is first-class citizen;
  • Operations in the program should map input values to output values rather than modify the data on the spot. Methods should not have side effects.

1.3 Advantages of Scala

1. Java compatibility

Scala works seamlessly with Java and is compiled into JVM bytecode on execution, making it performance on par with Java. Scala directly calls methods in Java, accesses fields in Java, inherits Java classes, and implements Java interfaces. Scala heavily reuses and wraps native Java types and supports implicit conversions.

2. Concise grammar

Scala programs tend to be compact and have significantly fewer lines of code than Java, making code read and understood faster and with fewer bugs.

3. Features of high-level languages

Scala is a high-level language-specific abstraction of code that allows you to control complexity and develop efficiently.

4. Static type

Scala has a very advanced static typing system. Scala not only has a Java-like type system that allows classes to be nested, it also supports parameterization of types using generics, intersection to combine types, and abstract types to hide type details. With these features, secure and easy-to-use programs and interfaces can be designed more quickly.

2. Configure the IDEA development environment

2.1 Prerequisites

Scala relies on the JDK to run, and Scala 2.12.x requires JDK 1.8+.

2.2 Installing the Scala Plug-in

IDEA does not support Scala development by default. You need to use plug-ins to expand IDEA. Open IDEA and click the File => Settings => plugins TAB in turn to search for Scala plug-ins (as shown below). After the plug-in is found, install it and restart IDEA for the installation to take effect.

2.3 Creating a Scala project

In IDEA, click the File => New => Project TAB, then select Create Scala — IDEA Project:

2.4 Downloading the Scala SDK

1. The way a

When you see that the Scala SDK is empty, click Create => Download, select the required version and click OK button to Download it. After downloading, click Finish to enter the project.

2. 2

Method one is the method used in Scala’s official installation guide, but the download speed is usually slow and Scala command line tools are not provided directly under this installation. Therefore, I recommend downloading the installation package from the official website at www.scala-lang.org/download/

Here MY system is Windows, download the MSI version of the installation package, keep clicking next to install, after the installation is completed, the environment variables will be automatically configured.

Since environment variables are automatically configured during installation, IDEA automatically selects the corresponding SDK version.

2.5 Creating a Hello World

Create hello.scala by right clicking New => Scala class in the project SRC directory. Enter the code as follows and click the “Run” button after completion. Successful operation means successful construction.

2.6 Switching the Scala Version

In daily development, if the version of the corresponding software (such as Spark) needs to be changed, you can switch the Version of Scala in the Global Libraries TAB of Project Structures.

2.7 Using the Scala Command Line

Using MSI installation, the program will automatically configure environment variables. In this case, you can directly use the command line tool:

The resources

  1. Martin Odersky(Written), Gao Yuxiang (translated). Scala Programming (3rd edition)[M]. Publishing House of Electronics Industry. 2018-1-1
  2. www.scala-lang.org/download/

See the GitHub Open Source Project: Getting Started with Big Data for more articles in the big Data series