<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

    主站蜘蛛池模板: 一区二区三区在线免费看 | 国产免费看插插插视频| 成人毛片18女人毛片免费视频未| 欧美好看的免费电影在线观看| www亚洲一级视频com| 亚洲精品无码MV在线观看| 亚洲一区二区三区四区在线观看| 亚洲色丰满少妇高潮18p| 一个人看的www免费高清 | 一个人看www在线高清免费看 | 亚洲av成人一区二区三区在线播放| 在线播放免费人成毛片乱码| 看全色黄大色大片免费久久| 黑人精品videos亚洲人| 日本免费电影一区二区| 国产亚洲精品a在线观看| 日本亚洲免费无线码| 无码A级毛片免费视频内谢| 中文字幕亚洲综合久久| 日韩免费电影网址| 亚洲乱码卡三乱码新区| 插鸡网站在线播放免费观看| 成人毛片免费网站| 人妻无码中文字幕免费视频蜜桃| 亚洲性线免费观看视频成熟| 亚洲一区二区三区日本久久九| 美女视频黄免费亚洲| 色多多A级毛片免费看| 亚洲A丁香五香天堂网 | 国产亚洲国产bv网站在线| 久久一本岛在免费线观看2020| 亚洲国产精品综合久久2007| 99在线免费观看视频| 久久亚洲国产午夜精品理论片| 免费看美女午夜大片| 久久久久久久久亚洲| 免费一区二区无码东京热| 亚洲av无码一区二区三区天堂古代| 精品无码国产污污污免费网站| 国产亚洲午夜高清国产拍精品| 四虎www免费人成|