(Super detailed) Scala environment construction (scala-2.12.15, IDEA2021.1.3)

Scala environment construction (scala-2.12.15, IDEA2021.1.3)

JunLeon——go big or go home


 Table of contents

Scala environment construction (scala-2.12.15, IDEA2021.1.3)

1. Overview of Scala

1. What is Scala?

2. History of Scala development

3. The relationship between Scala and Java

2. Scala environment construction

1. Environment preparation

2. Scala installation and configuration environment variables

3. Verify Scala

3. Write your first Scala program

1. Use IDEA to create a maven project

2. Install the Scala plugin

3. Create scala file

4. Running results


Foreword:

        To learn Scala, it is best to master the basics and advanced knowledge of Java. The connection between Scala and Java will be mentioned in the text of the article. Simply speaking, Scala is like an enhanced version of Java, because Scala is a Java virtual machine ( JVM ) Environment and a statically typed programming language that combines the best features of object-oriented and functional programming (static languages ​​need to be compiled in advance, such as: Java, c, c++, etc., dynamic languages ​​such as: js).

1. Overview of Scala

1. What is Scala?

Scala is a statically typed programming language that uses the Java Virtual Machine (JVM) as the operating environment and combines the best features of object-oriented and functional programming (static languages ​​need to be compiled in advance, such as: Java, c, c++, etc., Dynamic language such as: js).

  1. Scala is a multi-paradigm programming language, Scala supports object-oriented and functional programming . (Multi-paradigm means multiple programming methods. There are four programming methods: process-oriented, object-oriented, generic, and functional.)

  2. Scala source code ( .scala ) will be compiled into Java bytecode ( .class ), and then run on the JVM, and can call the existing Java class library to achieve seamless connection between the two languages.

  3. Scala, as a language alone, is very concise and efficient .

  4. When designing Scala, Martin Odersky referred to the design ideas of Java. It can be said that Scala originated from Java. At the same time, Martin Odersky also added his own ideas, integrating the characteristics of functional programming languages ​​into In JAVA, therefore, for students who have studied Java, as long as they understand the similarities and differences between Scala and Java in the process of learning Scala, they can quickly master the language of Scala.

2. History of Scala development

  • 2001 Martin Odersky of EPFL begins designing Scala based on Funnel's work.

    Funnel is a programming language that combines functional programming ideas with Petri nets. Odersky previously worked on Generic Java and javac.

    Martin Odersky is a fan of compilers and programming. After programming for a long time, he hopes to invent a language that can make basic work such as writing programs efficient and simple. So when I came into contact with the JAVA language, I became very interested in JAVA, a portable language that runs on the Internet and has garbage collection, so I decided to integrate the characteristics of functional programming languages ​​​​into JAVA, and thus invented two languages ​​(Pizza & Scala).

  • Late 2003/early 2004 Scala for the Java platform was released.

  • In June 2004, Scala for the .NET platform was released.

  • Scala v2.0 was released in March 2006 .

  • In April 2009 Twitter announced that they had migrated most of their back-end programs from Ruby to Scala, and planned to migrate the rest. Furthermore, Wattzon has publicly stated that its entire platform has been written on top of the Scala infrastructure.

  • In 2014, when Martin Odersky announced that Scala 2.12 would simplify the syntax and launched the Scala "Don Giovanni" project, he said: "Scala is created for smart people now, and will serve smart people in the future."

  • In 2020, Scala 3.0.0 was released, adding many exciting new features including Dynamic Partition Pruning, Adaptive Query Execution, Accelerator-aware Scheduling, and support for Catalog Data Source API with Catalog Supports, vectorization in SparkR (Vectorization in SparkR), support for Hadoop 3/JDK 11/Scala 2.12, etc.

3. The relationship between Scala and Java

Scala is based on Java, so we need to clarify the relationship between Scala, Java and JVM first.

2. Scala environment construction

1. Environment preparation

jdk -- > jdk-8u321-windows-x64.exe

Official Downloads: Java Downloads | Oracle

scala --> scala-2.12.15.zip

   Official download: Scala 2.12.15 | The Scala Programming Language

2. Scala installation and configuration environment variables

Java JDK must be installed before installing scala

For jdk installation, please check: (Super detailed) The latest version of java 8 (jdk1.8u321) installation tutorial in 2022_JunLeon's Blog-CSDN Blog

1) unzip scala

Unzip the downloaded Scala compressed package to a specified location, such as: D:\software\ directory

Mine is in D:\Program Files\scala-2.12.15, configured according to my own path

2) Configure environment variables

The steps to configure Scala environment variables and configure jdk environment variables are the same

step:

Right-click properties of my computer (win11 finds about in the system control panel) --> Advanced system settings --> Environment variables

New variable:

Variable name: SCALA_HOME

Variable value: D:\Program Files\scala-2.12.15

 System variables --> PATH , select PATH, edit. Configure %SCALA_HOME%\bin

After configuration, click OK all the way.

3. Verify Scala

Open the Windows operation (you can open it with the win+R shortcut key), enter cmd

Enter scala

 

3. Write your first Scala program

1. Use IDEA to create a maven project

1)File --> new --> Project

 2) Choose to create a Maven project, choose your own JDK, the next step:

  3) Enter the project name and the path where the project is stored

 4) Create the project as follows:

2. Install the Scala plugin

Originally IDEA does not support Scala, so a plug-in needs to be installed to enable IDEA to support Scala. The installation steps are as follows:

Method 1: Use IDEA to download and install the plug-in

File --> Settings --> Plugins --> Searchfor Scala

 

Method 2: Download the plug-in on the official website, pay attention to the corresponding idea version

Download address: Scala - IntelliJ IDEs Plugin | Marketplace

My idea is version 2021.1.3, and the downloaded one is scala-intellij-bin-2021.1.3.zip

After downloading, import the plug-in in the idea, File --> Settings --> Plugins to find the setting button next to it,

Install Plugin from DiskImport the downloaded plugin

3. Create scala file

Before creating the .scala file, it is found that the creation of the scala file is not found in new, you need to add the Scala framework

1) Add Scala framework

Right click on the project --> Add Frameworks Support --> check Scala (at the bottom, slide down)

2) Create a scala file

3) Write your first Scala program

Create Objecta singleton, the command is HelloWorld

Create the main method and print out "Hello World"

package com.junleon

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello World")
  }
}

4. Running results

The first compilation needs to build the project, it may be a bit slow, just wait for a minute or two

   After running, you can see the output Hello World in the console

Next: Scala variables and data types

If you like it and it is helpful to you, like + bookmark, and learn knowledge from Brother Jun...

Guess you like

Origin blog.csdn.net/JunLeon/article/details/122633865