Scala Programming – Setup

As a part of the new environment, I start to learn this functional programming language called Scala Programming. I sign up the Coursera’s course, Functional Programming Principles in Scala. The course began in May 2017.

Therefore, most of my write-up on Scala is be based on the Coursera’s course and some of the experience I gained from my hand-on or on-job-training.

Before I start coding, there is a few things need to be installed and configured before I can start the basic print out “Hello World”. Let me walk through the setup processes here. My machine is running on the virtual machine with Ubuntu 16.04 installed.

Installing the JDK

The first thing first is installing the Java Development Kit. At the point of my learning, its latest version is JDK 8.0. To install JDK on the Ubuntu, we need to run a command in the Terminal. So, let’s open the Terminal and put the below code,

sudo apt-get install openjdk-8-jdk

It will prompt you to enter user password of your machine and it will proceed to get it installed. For other Linux operating systems, there are other commands to be run. To check the installed Java version, you can type the below command in the terminal.

java -version

You can expect to see the detail as below,
ubuntu16-04@ubuntu:~$ java -version
openjdk version “1.8.0_121”
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

Alternatively, you can install the JDK manually by downloading the .tar.gz archived file from the Oracle website, unzipped it at the preferred directory and add the bin/ directory of the extracted JDK to the PATH environment variable.

Installing sbt

Okay, what is sbt?

sbt is an open source build tool for Scala and Java projects, similar to Java’s Maven or Ant. This is a definition I found from the Internet. There is an online document you can read up for ‘Getting Started with sbt’, http://www.scala-sbt.org/0.13/docs/Getting-Started.html. I refer to this online document to install sbt on Linux. For other operating systems, you can refer to the relevant document.

echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt

Installing IntelliJ

For the Coursera’s course, the instructor teaches us to install the IntelliJ IDEA. You can choose to install other IDEs such as Eclipse, Sublime and etc. It is your own preferences. For my virtual machine, I will follow the Coursera’s course to use the IntelliJ. The installer can be found from its website, https://www.jetbrains.com/idea/download/#section=linux.

Proceed to download the Community version .tar.gz file. Upon completion, change directory to the file location. You can run the command below to check the file too.

Next, we need to extract the file and begin to install it on our machine by navigating to the bin folder and run the idea.sh. Pardon me for the wrong change directory in the screenshot below.

Viola! The IntelliJ’s first screen prompts up. Go along with the step by step setup until you click the ‘Finish’ button. The customization of IntelliJ IDEA allows us to set the UI Theme, create desktop entry for integration with system application menu, create launcher script which allows us to open files or projects from the command lines, install plugin in which Scala must be installed before we start using it.

So, what is next? Of course we shall create a Scala project and have our very first program runs. Let us give a try and not just finish here… You will get to see UI of IntelliJ with options to a create project, import project and etc on the screen as below,

And yes, we are just two more steps nearer to the first Scala program. Click on the ‘Create New Project’. In the screen below, select the Scala > SBT > Next button.

It brings us to the next page where we fill in the project name and check on the JDK, SBT and Scala properties. Remember that we have done the JDK installation in the first step, then followed by the SBT installation before we began our IntelliJ installation whereby we did the Scala installation too?

Click on the ‘Finish’ button and it creates the project for us. The interface looks as below when it launches on my virtual machine which is running on Ubuntu 16.04.

Last step is start learning how to code! Keep it up!

Advertisements

So You Want To Be A Developer? [Part 3]

I am sorry I took a short break from writing blogs in order to concentrate and complete my final project for the Data Science Course that I am taking. It has been a long journey of 1 year to complete this course. Of course, I did take a month break from it before I finished my final project. It is really not a good idea to take a break from study.

In the part 3 of the “So You Want To Be A Developer?”, the third question the host asked the speaker was how do they learn the programming language and which language that they would suggest for beginner.

Most of them did not really specific which language to pick but did suggest if you do not have programming background, learn Javascript is the best to kick start. What do you think?

Personally, I agreed we can learn any languages that we like. It depends on individual and some may find it easy while some have to struggle in the beginning. Once you are getting familiar, you will be okay and when you keep doing, you will find yourself creating magic tools. Everything is just a click away.

I started with Visual Basic 6.0 and I jumped into .net immediately after learning Java. Do not ask me why. I did well for Java and badly for Visual Basic. Do you believe it? In the end, I decided to choose .net C# as my main language until now. I learned all by examples from the Internet, forums and books that I borrowed from the library during my college time. When I started to work, colleagues and Google have become my best pals to learn the language. Due to work nature, I stick with C# for the past 6 years and now I feel it is time to move on to learn others.

Recently, Python and Ruby on Rails are getting popular but young developers. Maybe, we should try it out. How about you, have you thought of which language you want to try?