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.
First, I want to say some things about Scala. It has some properties like:
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)
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
sudo apt-get install openjdk-7-jdk
apt-cache search jdk
## check install successfully
If you have install wrong Scala version (2.9). You can remove it first
sudo apt-get remove scala-library scala
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.
Open IntelliJ plugin manager (File -> setting -> plugins)
Choose Browse repositories button at the bottom bar on the right and type Scala in the Search box.
Install Scala (Custom Language) – which one has over 2 million times of installations
Restart IntelliJ (you may even need to login your computer again)
Now create new project
File, then new project
Choose Scala on the left, non-sbt on the right
Choose Project SDK is your Java JDK
Set Scala home – may it be in /usr/local/share/scala
The final one is for your work! create Scala files
Right-click src folder –> Package
Type the package name HelloWorld. Then, right-click the newly created package and choose Scala Class
The next prompt window, type helloworld on name and choose kind Object, not class
Your HelloWorld.scala file should look like this
* Created by quyetdc on 09/09/2014.
Run or Alt+Shift+F10
All your hard works are done perfectly? Congratulation! if not, please do not feel hesitate to contact me!