Scala Hello World Example

0

In this article, we will see a hello world example of scala with which I will start my new series on Scala.

So let’s start with a brief definition on scala and some important links to get you started.

Brief About Scala

Scala stands for ‘Scalabale language’. It is a statically typed language. It runs on the standard Java platform. It is a mix of object-oriented and functional programming concepts. The main strength is its functional programming ability.

The version I am using is 2.11.6.

Setup Scala

First download Scala and run the installer.
Open your command prompt and type-in scala. It should start the interactive Scala interpreter.

Scala Interpreter

Scala Interpreter

Now install the IDE. You may want to use Scala IDE for Eclipse or IDEA. In case you already have IDEA, just download the Scala Plugin.

Scala Hello World Program

To print ‘Hello World’, you can even use the Scala Inerpreter.

scala> println("Hello, world!")
Hello, world!

Let’s create our first scala program in Eclipse.
Create a new scala project. Open File->New->Scala Project.
Right click on default package. Next, click New->Scala Object. Enter ‘HelloWorld’ and finish.

Paste in the below code.

HelloWorld.scala:

  object HelloWorld {
    def main(args: Array[String]) {
      println("Hello, world!")
    }
  }

Right Click on the scala file name and click on ‘Run As’->’Scala Application’.

Output:

Hello, world!

Download source code

In this article, I show you a ‘Hello World’ example of Scala. You can download the source code here: HelloWorldExample.zip

Share.

Comments are closed.