<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 閱讀(238) 評(píng)論(0)  編輯  收藏 所屬分類: Scala / Java

    主站蜘蛛池模板: 亚洲国产成a人v在线| 国产精品国产午夜免费福利看| 美女被暴羞羞免费视频| 亚洲码欧美码一区二区三区| 亚洲欧洲无码AV不卡在线| 永久在线免费观看| 国产成人免费a在线视频色戒| 亚洲欧洲校园自拍都市| 国产成人高清亚洲一区久久| 久久久受www免费人成| 久久99免费视频| 永久看日本大片免费35分钟| 亚洲欧洲在线观看| 亚洲人av高清无码| 四虎影视免费在线| 久久99亚洲综合精品首页| 国产V亚洲V天堂无码| 亚洲综合久久一本伊伊区| 在线观看国产一区亚洲bd| 久久久久久久久久久免费精品| 又粗又大又长又爽免费视频| 亚洲精品国产成人专区| 香港a毛片免费观看| 国产网站在线免费观看| 无码一区二区三区亚洲人妻 | 亚洲综合色婷婷在线观看| www成人免费视频| 国产精品成人免费一区二区| 久久精品九九亚洲精品天堂| 2020因为爱你带字幕免费观看全集| 亚洲一级毛片免观看| 91香蕉国产线观看免费全集| 亚洲电影日韩精品| 中国亚洲呦女专区| 99久久99这里只有免费费精品| 精品亚洲综合久久中文字幕| 永久免费在线观看视频| 美女扒开屁股让男人桶爽免费| 亚洲第一极品精品无码久久 | 免费观看黄色的网站| 国产日韩成人亚洲丁香婷婷|