From Java to Scala


(T) Martin Odersky, a professor at the Ecole Polytechnique Federale de Lausanne (EPFL) in Switzerland and author of Scala (Scalable Language) recently came to Silicon Valley and presented the new features of Scala 2.1 in a few meet-ups (What’s Next for Scala: ScalaNext.pdf). Scala is gaining some market tractions for large scale business applications. Businesses want to maximize the productivity of their developments while designing and implementing applications that are reliable and scalable. At Twitter, for instance, the core messaging queue of Twitts was redesigned in Scala to better scale due to the exponential increase in the number of Twitts with only 1,500 lines of codes. Twitter Software Engineer Robey Pointer made that (his) code available as an open source project:

Scala is the fruit of early work from Martin Odersky to improve Java for scalable and concurrent programming. To that end, while all the object-oriented programming features of Java have been kept, Scala changed the syntax of Java in order to provide functional programming. The result is that Scala is a general-purpose programming language which provides seamless integration to Java while reducing code sizes by 2 to 3 compared to Java programming. The Scala compiler produces compatible Java byte-codes that can run on the Java VM. Scala programs can leverage existing Java libraries and can call Java programs (the reverse is also true).

While Java was adopted overnight by the industry as the language for Internet applications in 1995, Scala, which was started in 2003, is slowly getting more traction.

Feature Details (from

Object-oriented programing:
In Scala, every value is an object. Types and behavior of objects are described by classes and traits. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritances.

Functional programming:
In Scala, every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala’s case classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.

Scala’s notion of pattern matching naturally extends to the processing of XML data with the help of right- ignoring sequence patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.

Statically typed:
Scala provides an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. In particular, the type system supports:
 generic classes
 variance annotations
 upper and lower type bounds
 inner classes and abstract types as object members, compound types
 explicitly typed self-references
 polymorphic methods

A local type inference mechanism takes care that the user is not required to annotate the program with redundant type information. In combination, these features provide a powerful basis for the safe reuse of programming abstractions and for the type-safe extension of software.

In practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries: any method may be used as an infix or postfix operator, and closures are constructed automatically depending on the expected type (target typing).

Joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.

Code Examples


Copyright © 2005-2012 by Serge-Paul Carrasco. All rights reserved.
Contact Us: asvinsider at gmail dot com.