Home > JEE, Open Source > Scala – Step by Step!!

Scala – Step by Step!!

Print Friendly Print Get a PDF version of this webpage PDF

I decided to learn Scala when I saw a piece of code written by one of my colleagues. I was amazed with its conciseness. But I failed at my first attempt to learn this language. I know the reason why. I read some stuff without writing enough code. After couple of days, all the syntax was washed out of my head. You have to train yourself to forget some Java syntax for time being while you are writing Scala code and train your fingers with the new syntax. Don’t get drunk with Scala, Drink it slowly!! Don’t expect that after reading a book you would be fully functional to write Scala code for production. If you don’t find these difficulties while learning Scala, you must be a Geek!! I envy you!! But I’m sorry, the following blog post is not for you.

Which Book?

Buy a book by the Scala daddy Martin Odersky – Programming in Scala. Go read some stuff from Scala website.

Which IDE to use?

They say, best way to learn any new language is to write code in vi editor. I did that when I learnt Java. But now, I don’t enjoy writing code in vi editor. I don’t want to make life complicated, I prefer using IDE’s.

Since last couple of months I’m using Spring STS which works quite well. So I thought of using Eclipse for my Scala exercises. I installed the Scala IDE plugin, the project was compiled properly using maven scala plugin, but was showing errors in the IDE. Some versioning issue. I didn’t want to struggle further, and tried the same in IntelliJ. Installed the Scala plugin. It just worked and I wasn’t surprised. Well it’s IntelliJ!!

Creating Scala Project:

To create a maven scala project, you can use the following archetype.


mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple  -DarchetypeVersion=1.2 -DremoteRepositories=http://scala-tools.org/repo-releases -DgroupId=net.arunoday -DartifactId=scala-demo

Open pom.xml. Change the scala version to 2.8.0.RC7. Add the following dependency.

    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-compiler</artifactId>
        <version>${scala.version}</version>
        <scope>compile</scope>
    </dependency>

Import the maven project in IntelliJ. The sample project contains a scala class App.scala and a test AppTest.scala

object App extends Application {
  println( "Hello World!" );
}

package net.arunoday

import org.junit._
import Assert._

@Test
class AppTest {

    @Test
    def testOK() = assertTrue(true)
}

That covers very basic steps to get started with scala. Once this project setup is done, you are all set to write some scala code on your own. More on this later. Stay Tuned!!

Categories: JEE, Open Source Tags:
  1. No comments yet.
  1. No trackbacks yet.
Get Adobe Flash playerPlugin by wpburn.com wordpress themes