Tags

, , , , ,

By following the below steps, you will get success in your first program in Scala.

To work with scala, below are the tools we need.
1. Java SDK 1.6 or higher
2. SBT, a build tools for scala
3. Scala IDE for eclipse.

SDK setup
1. Verify whether you have installed with Java 1.6 or higher. If you dont have download and install it from oracle website.
2. Set the java in path ( path=%path%;%JAVA_HOME%/bin;)

SBT setup for windows
1. Download the SBT from the official site (http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.12.2/sbt.msi)
2. Unpack the archive to a directory of your choice.
3. Set the SBT in path (path=%path%;%JAVA_HOME%/bin;%SBT_HOME%/bin;

Here %SBT_HOME% represents the place where you copied the SBT archive. Replace %SBT_HOME% with your directory.

Once the path has set, verify that SBT is installed correctly. By running the command “sbt sbt-version” you can verify the SBT installation in command window. If any issues, please correct your path setup.

Scala IDE for eclipse
You can download the Scala IDE for eclipse with the Scala Worksheet pre-installed from the following URL:
http://typesafe.com/stack/scala_ide_download (Make sure to download the IDE for Scala version 2.10.1)
Your First program
To begin with hello world in scala, follow the below steps.

1. On eclipse, go to File –> New –> Scala Project.

2. Give the project name ( For eg, scala-test )

3. Make sure the execution environment JRE is JAVASE-1.6 or higher.

4. Click Finish. Your project will be created.

5. Right click on src in your project and click New –> Scala Object.

6. Enter the package ( for eg, com.test ) and name (For eg, Helloworld) and click Finish.

7. Copy the below code in your Helloworld.scala source file.

package com.test

object Helloworld extends App {

println(“This is my first program”);
}

8. Save the file and select “Run as – Scala application”. Your output will be printed in console.

Advertisements