Home » TechNote » Scala: First step to move on!

Scala: First step to move on!

Hi everyone!

Today I am going to help you, especially for developers who use Ubuntu as working OS, get start with Scala: install, create first application and use an IDE.

scala

First, I want to say some things about Scala. It has some properties like:

  • Functional Programming
  • Flexible Object Oriented Programming (trait)
  • Write less, do more
  • There no need to use ; as in C++, C, Java, C#.
  • Scala Interpreter (often called a REPL for Read-Evaluate-Print Loop)
  • Fast.
  • Can add Java code.
In my opinion, Scala is worth for trying! However, If you do neither have experience on Java nor OOP but familiar with flexible-syntax language like Ruby, you may get a little difficulty in using this language. But do not worry. At least, you can create a Scala “hello word!” program in IntelliJ IDEA, another IDE of Jetbrains (where RubyMine was born) after follow this article.

OK, let’s move on!!!

The first thing you need is to be sure you have installed Java JDK. You can simply install it via Ubuntu software center.

Or try this


Install Scala.
If you have install wrong Scala version (2.9). You can remove it first

After that, install newer version of Scala (2.11.2)


Now, you can interact with Scala on your terminal, try

Then you can play some code from scratch with Scala


However, I think it is better for both you and me to have an Integrated Development Environment, such as IntelliJ IDEA. You can download it from http://www.jetbrains.com/idea/download/. I chose the Community Edition, which is free.

After finishing download, extract it. Then go to the extracted folder, then /bin and type

It is not enough until now. Please add Scala plugin into INtelliJ and then everything is done.

  1. Open IntelliJ plugin manager (File -> setting -> plugins)
  2. Choose Browse repositories button at the bottom bar on the right and type Scala in the Search box.
  3. Install Scala (Custom Language) – which one has over 2 million times of installations
  4. Restart IntelliJ (you may even need to login your computer again)

Now create new project
  1. File, then new project
  2. Choose Scala on the left, non-sbt on the right
  3. Choose Project SDK is your Java JDK
  4. Set Scala home – may it be in /usr/local/share/scala

The final one is for your work! create Scala files
  1. Right-click src folder –> Package
  2. Type the package name HelloWorld. Then, right-click the newly created package and choose Scala Class
  3. The next prompt window, type helloworld on name and choose kind Object, not class
  4. Your HelloWorld.scala file should look like this

  5. Run or Alt+Shift+F10
All your hard works are done perfectly? Congratulation! if not, please do not feel hesitate to contact me!
ありがとう ございます。