|
||||||
How to Get Started with Programming in ScalaCreating Applications with Scala Computer ProgrammingScala is a free, functional, object oriented programming language for the experienced Java programmer and it is even suitable for programming for beginners
There's no doubt that President Obama will go down in history for many things, and one of those things is that the online traffic during his inauguration helped Twitter to decide to move to the Scala programming language for their message queueing system. And the great thing is that any programmer can start to understand why that was because this object oriented functional programming language is completely free to download and use. Obtaining and Installing ScalaThe Scala programming language can be obtained from http://www.scala-lang.org. It does not need installing, just unpacking into a suitable directory. However, it will need some system environment variables setting. These are:
It will also require the Java runtime to be installed, although it is worth noting that some IDE's (Integrated Design Environments) already support Scala development, and there are Scala plugins for:
However, all that's actually needed is a console (such as a Linux shell or the Windows command prompt) and a simple text editor. Starting Scala in Interactive ModeOnce the system environment variables have been set up correctly then Scala can be started in interactive mode by going to the command line and typing: scala
This will start an interactive session and the programmer can start programming in Scala, in this case to create a simple "Hello World" object: object Hello {
def main (args: Array[String]) {
println ("Hello World")
}
}
In this example Scala will respond that it's "defined module Hello", and then the programmer can run the code: Hello.main (null)
And the text "Hello World" will be displayed on the screen (as can be seen in figure 1). It's worth noting at this point that Scala is case sensitive, and so the following will result in an error message being displayed: hello.main (null)
Of course, regardless of the case of the letters, this is an impractical way of developing a full Scala application. It is only really suitable for testing and training purposes. In programming Scala, therefore, the programmer must look at other ways of running the code. Compiling and Running Scala CodeIf the code for the "Hello" Scala object is saved to a file named "Hello.scala" then the programmer can use the scalac program to compile it: scalac Hello.scala
And then it can be run: scala Hello
It will display the same text as before (as shown in figure 2), but now the programmer can carry on programming in Scala and then passing their applications on to all of their users to enjoy.
The copyright of the article How to Get Started with Programming in Scala in Computer Programming Languages is owned by Mark Alexander Bain. Permission to republish How to Get Started with Programming in Scala in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||