Free tutorials for Java, Eclipse and Web programming



Scala development with Eclipse - Tutorial

Lars Vogel

Version 1.7

22.11.2009

Revision History
Revision 0.114.02.2009Lars Vogel
First version - Draft
Revision 0.214.06.2009Lars Vogel
Added Eclipse installation, first scala example
Revision 0.315.06.2009Lars Vogel
Variables in Scala
Revision 0.423.08.2009Lars Vogel
Bug report for first scala project
Revision 0.524.08.2009Lars Vogel
Added JDT Weaving
Revision 0.625.08.2009Lars Vogel
Hello Scala World working
Revision 0.721.09.2009Lars Vogel
Functions
Revision 0.822.09.2009Lars Vogel
Loops
Revision 0.909.10.2009Lars Vogel
Collections
Revision 1.010.10.2009Lars Vogel
Added clean tip
Revision 1.122.10.2009Lars Vogel
Added case clases
Revision 1.204.11.2009Lars Vogel
Added recursive functions
Revision 1.308.11.2009Lars Vogel
Class and constructors, objects
Revision 1.412.11.2009Lars Vogel
override
Revision 1.5 14.11.2009Lars Vogel
Method names, traits
Revision 1.621.11.2009Lars Vogel
uniform access principle
Revision 1.722.11.2009Lars Vogel
switch

Scala development with Eclipse

This article explains how to develop Scala with Eclipse. It also explains several base features of Scala. The article is based on Scala 2.7 and Eclipse 3.5.


Table of Contents

1. Scala
2. Installation
2.1. Eclipse Scala plugin
2.2. Enable JDT Weaving
3. Your first Scala project
4. Variables
5. Classes and Objects
5.1. Overview
5.2. Constructor
5.3. Inheritance
5.4. Objects
5.5. Companion Objects
6. Functions (Methods)
6.1. Using Functions
6.2. Method names
6.3. Override
6.4. Uniform access principle
7. Loops
8. Collections
8.1. List
8.2. Array
8.3. Maps
8.4. Methods for Collections
9. Case Classes
10. Traits
10.1. Overview
10.2. Example
11. Thank you
12. Questions and Discussion
13. Links and Literature
13.1. Source Code

1. Scala

Scala stands for scalable language which indicates that Scala is suitable for small scripting tasks as well as large enterprise applications. The creator of Scala is Martin Odersky.

Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. Scale compiles to Java bytecode and therefore runs on the JVM.

Scala is a hybrid language, it is a object-orientated progrmaming languate as well a functional programming language.

Skala has objects and classes. Objects are singletons and are defined via the keyword "object". Classes are defined via the keyword "class".

Scala does not support primitive types, everything is Scala is an object, e.g. the number 1 is an object and has methods.

Methods can use special signs, e.g. +, -, ->, =>. For example the sign "+" is a method defined for the Object integer. As Scala allows you to avoid the dot and the braces if a method has only one parameter you still can write 1+2 but this really means 1.+(2) and is a method call to the method "+" to the instance 1 of object integer.

Scala tries to be very concise, for example semicolons at the end of a line are optional. Scala follows the uniform access principle , which describes that the access to method invocation and field selection should be the same (this principle was taken from the programming language Eiffel).