Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Scala Programming

You're reading from  Learning Scala Programming

Product type Book
Published in Jan 2018
Publisher Packt
ISBN-13 9781788392822
Pages 426 pages
Edition 1st Edition
Languages
Author (1):
Vikash Sharma Vikash Sharma
Profile icon Vikash Sharma

Table of Contents (21) Chapters

Title Page
Packt Upsell
Contributors
Preface
1. Getting Started with Scala Programming 2. Building Blocks of Scala 3. Shaping our Scala Program 4. Giving Meaning to Programs with Functions 5. Getting Familiar with Scala Collections 6. Object-Oriented Scala Basics 7. Next Steps in Object-Oriented Scala 8. More on Functions 9. Using Powerful Functional Constructs 10. Advanced Functional Programming 11. Working with Implicits and Exceptions 12. Introduction to Akka 13. Concurrent Programming in Scala 14. Programming with Reactive Extensions 15. Testing in Scala 1. Other Books You May Enjoy Index

Working with Scala


In this book, we're using Scala version 2.12.2. Scala 2.12 requires your system to have Java version 8 installed. Older Scala versions support Java version 6 and above. Support for Java version 9 is still a topic of discussion for the Scala 2.13 roadmap.

Scala 2.12 was a step up from previous versions, mainly for support of Java and Scala lambda interoperability. Traits and functions are compiled directly to their Java 8 equivalents.

Java installation

Do the needful. If Java is not already installed on your machine, you may refer to Oracle's website at https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html for instructions on how to install Java for your operating system.

SBT installation

SBT, as the name suggests, is a Simple Build Tool. From managing all source files to their compiled target versions to downloading all dependencies, SBT helps you create a Scala application with ease. You can configure how your test cases run. SBT comes with various commands for such tasks.

To install SBT on your machine, perform the following:

  1. Go to http://www.scala-sbt.org/download.html.
  2. You may choose from the available options suitable for your operating system.

After installation, you may check the version, so open a command prompt/terminal and type this:

sbt sbt-version
[info] 0.13.11

You should get the corresponding version number.

Scala REPL

There is more than one way of interacting with Scala. One of them is using Scala Interpreter (REPL). To run Scala REPL using SBT, just give the following command in the command prompt/terminal:

sbt console

This command will run Scala REPL.

To run Scala REPL using Scala binary, perform the following:

  1. Go to https://www.scala-lang.org/download/.
  2. Download the latest Scala archive.
  3. Extract the archive to any directory.
  4. Set the directory path as environment variables as shown in https://www.scala-lang.org/download/install.html.
  5. Try running the scala command, it should look something like this:

If so, congrats. You've done it. Now it's asking you to type any expression. You may try typing any expression. Try anything, like 1 + 2 or 1 + "2". REPL is your playground to learn Scala.

Scala IDEs

After getting familiar with Scala REPL, now is the time to install IDE (Integrated Development Environment). There are options available to work with Scala in IDE. Choose what fits the best for you. Eclipse lovers can go for Scala IDE. To download:

  1. Go to http://scala-ide.org/download/sdk.html.
  2. You may choose from the available options suitable for your operating system.

If you're accustomed to IntelliJ IDE, you may go for the plugin download for SBT. This will enable you to create Scala applications. To get started with Scala development on IntelliJ IDE:

  1. Go to https://www.jetbrains.com/idea/download/.
  2. You may choose from the available options suitable for your operating system.
  3. After installation, go to File | IntelliJ IDEA | Preferences | Plugins and search for Scala.
  4. Click on Install | Apply.

With this, you're ready to work with Scala on IntelliJ IDE. If you're IDE neutral, you may choose whichever suits the best. We'll use IntelliJ IDE (Community Edition) version 2017.1 with SBT version 0.13.15 and Scala 2.12.2 version.

You have been reading a chapter from
Learning Scala Programming
Published in: Jan 2018 Publisher: Packt ISBN-13: 9781788392822
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 €14.99/month. Cancel anytime}