Scala Programming – Hello World


This is a continuation from the previous entry which I wrote about the Scala Programming’s setup and IDE installation. In the previous entry, we were successfully setup the JDK, sbt, Scala and installed the IntelliJ. The last step is start coding.

Besides using the IntelliJ, you can install and use other IDEs to write codes, for example, Eclipse. It is just a personal preferences. I asked my friends which tools that they are using for Scala programming and I received a standard reply from them, Eclipse.

As for my Coursera’s course, the instructor is using IntelliJ and I am going to use it in my virtual machine. I will try to use Eclipse as well on my Windows environment. Come, let try to write a Hello World program using the IntelliJ.

When the new project loads, the Project explorer on the left side shows the structure of the Scala project. Go to the src folder and expand it. Under the main folder > New Scala Worksheet > Enter file name. The text editor at the center of the application loads the new file. Type as below,

"Hello World"

And, press the ‘Run’ button on the top. It renders the result on the right side of the application. We need to include the double quotation in our codes.

This is our first helloworld. Different IDEs will show the result in different mode or presentation but the end result is the same. You can try to use the command line to run and print helloworld too. When I tried it using my virtual machine’s command line by typing scala, it prompted me an error. It is my very first time using command line in Ubuntu to run a scala program.

scala

It advised me to install the Scala using the command below. I just did as per advised.

sudo apt install scala

It took a while to install when I run it in my Terminal. Can someone highlight to me what causes the error? Does it mean that Scala installation on the IDEs is not the same as the Terminal?

When the installation is completed in the Terminal, I try again as below and it is correctly displaying the string input I entered.

This is Scala Programming! I am going to stop writing for a while and concentrating on learning this programming language. See ya 🙂

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s