<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Chan Chen Coding...

    Scala First Taste

    The "Hello, world!" Program

    As a first example, we use the standard Hello world program to demonstrate the use of the Scala tools without knowing too much about the language.

      object HelloWorld {     
          def main(args: Array[String]) {
             println("Hello, world!")
    }
    }

    The structure of this program should be familiar to Java programmers: it consists of the method main which prints out a friendly greeting to the standard output.

    We assume that both the Scala software and the user environment are set up correctly. For example:

    EnvironmentVariableValue (example)
    Unix
    $SCALA_HOME $PATH
    /usr/local/share/scala $PATH:$SCALA_HOME/bin 
    Windows
    %SCALA_HOME% %PATH%
    c:\Progra~1\Scala %PATH%;%SCALA_HOME%\bin

    Run it interactively !

    The scala command starts an interactive shell where Scala expressions are interpreted interactively.

    > scala   
    This is a Scala shell.
    Type in expressions to have them evaluated.
    Type :help for more information.
    scala> object HelloWorld {
    | def main(args: Array[String]) {
    | println("Hello, world!")
    | }
    | } defined module HelloWorld
    scala> HelloWorld.main(null)
    Hello, world!
    unnamed0: Unit = ()
    scala>:q

    The shortcut :q stands for the internal shell command :quit used to exit the interpreter.

    Script it !

    The above Scala program may also be run as a shell script respectively as a batch command (see the examples in the man pages of the scala command).

    The bash shell script script.sh containing the following Scala code (and shell preamble)

    #!/bin/sh
    exec scala "$0" "$@"
    !#
    object HelloWorld {
        def main(args: Array[String]) {
        println("Hello, world! " + args.toList)
        }
    }
    HelloWorld.main(args)

    can be run directly from the command shell:

      > ./script.sh

    Note: We assume here the file script.sh has execute access and the search path for the scala command is specified in the PATH environment variable.

    Compile it !

    The scalac command compiles one (or more) Scala source file(s) and generates Java bytecode which can be executed on any standard JVM; the Scala compiler works similarly to javac, the Java compiler of the Java SDK.

      > scalac HelloWorld.scala

    By default scalac generates the class files into the current working directory. You may specify a different output directory using the -d option.

      > scalac -d classes HelloWorld.scala

    Execute it !

    The scala command executes the generated bytecode with the appropriate options:

      > scala HelloWorld

    scala allows us to specify command options, such as the -classpath (or -cp) option:

      > scala -classpath classes HelloWorld

    The argument of the scala command has to be a top-level object. If that object is followed by the clause extendsApplication, then all statements contained in that object will be executed; otherwise you have to add a method main which will act as the entry point of your program.

    Here is how it looks like:

    object HelloWorld2 extends Application {   
        println("Hello, world!")
    }


    -----------------------------------------------------
    Silence, the way to avoid many problems;
    Smile, the way to solve many problems;

    posted on 2012-02-25 21:50 Chan Chen 閱讀(232) 評論(0)  編輯  收藏 所屬分類: Scala / Java

    主站蜘蛛池模板: 亚洲a∨国产av综合av下载 | 91亚洲自偷手机在线观看| 高潮毛片无遮挡高清免费| 日本一区二区三区日本免费| 亚洲欧美一区二区三区日产| 好大好深好猛好爽视频免费| 亚洲精品动漫免费二区| 日本免费无遮挡吸乳视频电影| 亚洲日韩AV一区二区三区中文| 日本一道高清不卡免费| 看一级毛片免费观看视频| 亚洲精品国产V片在线观看| 日韩成人毛片高清视频免费看| 亚洲一区视频在线播放| 野花香在线视频免费观看大全| 亚洲av无码国产精品夜色午夜| 色欲色香天天天综合网站免费| 亚洲精品福利网泷泽萝拉| 最近的免费中文字幕视频| 亚洲jizzjizz少妇| 亚洲人成无码www久久久| 99在线视频免费观看| 亚洲短视频在线观看| 免费涩涩在线视频网| 一级白嫩美女毛片免费| 久久亚洲AV午夜福利精品一区 | 久久99精品免费一区二区| 亚洲AV一宅男色影视| 91精品免费在线观看| 亚洲大码熟女在线观看| 毛茸茸bbw亚洲人| 99re免费视频| 亚洲精华国产精华精华液网站| 亚洲Av无码乱码在线znlu| 午夜爽爽爽男女免费观看影院| ASS亚洲熟妇毛茸茸PICS| 久久久久亚洲AV成人网| 精品福利一区二区三区免费视频 | 日日夜夜精品免费视频| 成人片黄网站色大片免费观看cn| 亚洲欧洲精品在线|