- Hands-On Data Analysis with Scala
- Rajesh Gupta
- 555字
- 2021-06-24 14:51:05
Installing IDE
There are several integrated development environment (IDE) tools that have support for Scala. JetBrains IntelliJ IDEA Community Edition is a great choice and has excellent Scala support.
Download and install JetBrains IntelliJ IDEA Community Edition (https://www.jetbrains.com/idea/download/) for your OS. Once the installation is complete, please follow these steps:
- Start IntelliJ IDEA Community Edition and accept all default suggested settings. It is always possible to back and change settings at any later point in time. Once this is done, you will see a screen similar to the following screenshot:
- Select Configure from the preceding screen (highlighted by red color arrow) and then select Plugins from the drop-down list. You will see a screen similar to the following screenshot:
- Install the Scala plugin by clicking Install from the screen aforementioned (highlighted by red color arrow). This action will download the Scala plugin and install it. Once this is completed, you will see a screen similar to the following screenshot:

- Now restart your IDE by selecting Restart IDE (highlighted by red color arrow). This will restart your IDE and make it ready for developing Scala code. Now you are ready to start using the IDE for writing Scala code.
Now let us create a sample Scala/SBT project called HandsOnScala by following the instructions at https://docs.scala-lang.org/getting-started-intellij-track/building-a-scala-project-with-intellij-and-sbt.html.
The following steps show how to create a new Scala-based SBT project:
- Click on Create New Project as shown in the following screenshot:

- Select on Scala and then click Next to move onto next step, as shown in the following screenshot:

- Make sure to select sbt as highlighted in the following screenshot:

- Specify a suitable name for your project. You also have the option of specifying the location where the project files will be stored on the local computer. By default, a folder in the home directory is selected as the project location. Please also note that you can select the following additional version details:
- JDK version
- SBT version
- Scala version
In most cases, you can use the default versions, as shown in the following screenshot, press Finish button to continue:

- Add Scala Framework Support to the project (if it has not already been selected), as shown in the following screenshot. This is very important because, without Scala Framework Support, the IDE will not treat this project as a Scala project and will prevent any Scala-related work in the IDE:

- Just like in Java, the Scala source code is organized into packages. Create a package called handson.example by expanding to src/main/scala and right-clicking on the folder shown in the following screenshot:

- Now you are ready to start writing Scala source code and can run it on your IDE. Create and run your first Scala worksheet called HandsOnScratchPad, as shown in the following screenshot:

Scala worksheets are great tools for exploring and understanding Scala APIs. You can conveniently see the code and its associated evaluation side by side.
With the preceding IDE set up and running, you are now ready to work on any Scala project using the IntelliJ IDE. You also have the option of conveniently exploring small code snippets of Scala using the Scala worksheet feature of the IDE. This IDE also comes with a debugger and many more features that help improve a developer's productivity.