-
15
pages
-
English
-
Documents
Description
A Scala Tutorialfor Java programmersVersion 1.3May 24, 2011Michel Schinz, PhilippHallerPROGRAMMING METHODS LABORATORYEPFLSWITZERLAND21 IntroductionThis document gives a quick introduction to the Scala language and compiler. Itis intended for people who already have some programming experience and wantan overview of what they can do with Scala. A basic knowledge of object orientedprogramming, especially in Java, is assumed.2 A first exampleAs a first example, we will use the standard Hello world program. It is not very fasci nating but makes it easy to demonstrate the use of the Scala tools without knowingtoo much about the language. Here is how it looks:object HelloWorld {def main(args: Array[String]) {println("Hello, world!")}}The structure of this program should be familiar to Java programmers: it consistsof one method called main which takes the command line arguments, an array ofstrings, as parameter; the body of this method consists of a single call to the pre defined methodprintln with the friendly greeting as argument. Themain methoddoes not return a value (it is a procedure method). Therefore, it is not necessary todeclare a return type.What is less familiar to Java programmers is the object declaration containing themain method. Such a declaration introduces what is commonly known as a single-ton object, that is a class with a single instance. The declaration above thus declaresboth a class calledHelloWorld and an instance of that ...
-
Publié par
-
Langue
English