Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Scala Programming Projects

You're reading from   Scala Programming Projects Build real-world projects using popular Scala frameworks such as Play, Akka, and Spark

Arrow left icon
Product type Paperback
Published in Sep 2018
Publisher Packt
ISBN-13 9781788397643
Length 398 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Mikael Valot Mikael Valot
Author Profile Icon Mikael Valot
Mikael Valot
Nicolas Jorand Nicolas Jorand
Author Profile Icon Nicolas Jorand
Nicolas Jorand
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Writing Your First Program FREE CHAPTER 2. Developing a Retirement Calculator 3. Handling Errors 4. Advanced Features 5. Type Classes 6. Online Shopping - Persistence 7. Online Shopping - REST API 8. Online Shopping - User Interface 9. Interactive Browser 10. Fetching and Persisting Bitcoin Market Data 11. Batch and Streaming Analytics 12. Other Books You May Enjoy

Setting up your environment

First things first, we need to set up our work environment. In this section, we will get all the tools and libraries, and then install and configure them on your computer.

Scala programs are compiled to Java bytecode, which is a kind of assembly language that can be executed using a Java Virtual Machine (JVM). You will, therefore, need to have a Java compiler and a JVM installed on your computer. The Java Development Kit (JDK) provides both components, alongside other tools.

You could develop in Scala using a simple text editor and compile your programs using the Scala Simple Build Tool (SBT). However, this would not be a pleasant nor productive experience. The majority of professional Scala developers use an Integrated Development Environment (IDE), which provides many helpful features such as syntax highlighting, autocompletion, code navigation, integration with SBT, and many more. The most widely used IDE for Scala is IntelliJ Idea from JetBrains, and this is the one we are going to install and use in this book. The other options are Scala IDE for Eclipse and ENSIME. ENSIME is an open source project that brings IDE-like features to popular text editors such as Emacs, Vim, Atom, Sublime, and VSC.

Installing the Java SDK

We are going to install the Oracle JDK, which includes a JVM and a Java compiler. On many Linux distributions, the open source OpenJDK is preinstalled. OpenJDK is fully compatible with the Oracle JDK, so if you already have it you do not need to install anything else to follow this book.

You might already have a Java SDK installed on your computer. We are going to check if this is the case. If you are using Windows, open a DOS Command Prompt. If you are using macOS or Linux, open a Terminal. After the prompt, type the following:

javac -version

If you have a JDK installed, the version of the installed compiler will be printed:

javac 1.8.0_112

If the version installed is greater than or equal to 1.8.0_112, you can skip the JDK installation. The version of Scala that we are going to use is compatible with JDK version 1.8 or 1.9.

If not, open the following URL, download the SDK for your platform, and follow the installation instructions given: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.

Installing IntelliJ IDEA

Go to https://www.jetbrains.com/idea/download. Download the community edition for your platform. The ultimate edition offers more features, but we will not use them in this book.

The following are the steps to install IntelliJ IDEA:

  1. Run IntelliJ Idea.
  2. Select the Do not import settings option:

  1. Choose a UI theme. I personally prefer Dracula, since a dark background saves battery on a laptop and is more gentle on the eyes:

  1.  Create a desktop entry by checking the options given:

  1. In the Create Launcher Script dialog window, check the create a script... checkbox. It will let you open files in IntelliJ from the command line:

  1. Customize the plugins. For each component, click on Customize... or Disable All. We will not need most of the plugins. You can only select the following:
  • Build Tools: Disable All.
  • Version Controls: Only keep Git and GitHub.
  • Test Tools: Disable All.
  • Swing: Disable.
  • Android: Disable.
  • Other Tools: Disable All and keep Bytecode viewer, Terminal, and YAML.
  • Plugin Development: Disable.

You can see the aforementioned plugins in the following screenshot:

  1. Install the featured plugins—some additional plugins are proposed for you to install, such as the Scala plugin and a tool to learn the essential features of IntelliJ.
  1. Click on the Install button for Scala and for the IDE Features Trainer, as shown in the following screenshot, and then proceed by clicking on Start using IntelliJ IDEA:

If you are already a Vim aficionado, you can install IdeaVim. Otherwise, I would recommend that you avoid it. I personally use it daily, but it took me some time to get used to it.
  1. Click on Create New Project | Scalasbt:

  1. Fill in the following details, as shown in the following screenshot:
  • Name: scala_fundamentals.
  • JDK: Click on New and then select the installation directory of the Oracle JDK.
  • sbt: Choose the version 1.0.4, check Sources.
  • Scala: Choose the latest version 2.12.x, for instance 2.12.4 (IntelliJ lists all the possible versions and will download the one you choose), and check Sources.
  • Click on Finish.

It is going to take some time depending on your internet connection's speed:

  1. You should see the following project structure:

You have been reading a chapter from
Scala Programming Projects
Published in: Sep 2018
Publisher: Packt
ISBN-13: 9781788397643
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image