<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

    主站蜘蛛池模板: 亚洲av色香蕉一区二区三区| 亚洲精品**中文毛片| 久久久久亚洲精品无码网址色欲 | 亚洲春色在线观看| 污污网站18禁在线永久免费观看| 亚洲熟妇无码八AV在线播放| 一区二区三区在线观看免费| 国产精品冒白浆免费视频| 亚洲精品乱码久久久久久V| 最近最好的中文字幕2019免费| 亚洲精品人成网在线播放影院| 成人特黄a级毛片免费视频| 亚洲色大成网站www尤物| 日韩免费毛片视频| 九九视频高清视频免费观看 | 亚洲国产AV一区二区三区四区 | 久久久受www免费人成| jlzzjlzz亚洲乱熟在线播放| 国产福利在线观看永久免费| 一本色道久久综合亚洲精品| 性无码免费一区二区三区在线| 亚洲精品中文字幕乱码| 操美女视频免费网站| 免费国产va在线观看| 亚洲精品无码精品mV在线观看| 久久狠狠躁免费观看| 亚洲av无码不卡久久| 国产精品视频免费一区二区三区| 成年网在线观看免费观看网址| 国产∨亚洲V天堂无码久久久| 久久国产免费福利永久| 亚洲综合成人婷婷五月网址| 免费v片在线观看品善网| 免费成人高清在线视频| 亚洲综合伊人制服丝袜美腿| www.亚洲精品.com| 久久精品无码专区免费青青| 亚洲国产aⅴ成人精品无吗| 亚洲综合图色40p| 97在线线免费观看视频在线观看 | 免费播放在线日本感人片|