<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

    主站蜘蛛池模板: 色婷婷综合缴情综免费观看| 亚洲国产精品午夜电影| 激情婷婷成人亚洲综合| 午夜成年女人毛片免费观看| 免费人妻无码不卡中文字幕系| 奇米影视亚洲春色| 丁香花在线视频观看免费| 国产中文在线亚洲精品官网| h片在线观看免费| 亚洲av永久无码精品国产精品| 华人在线精品免费观看| 亚洲国产综合专区电影在线| 久久永久免费人妻精品下载| 久久亚洲精精品中文字幕| 亚洲黄色免费观看| 亚洲中文字幕久久精品无码VA| 四虎成人免费大片在线| 曰批全过程免费视频免费看| 久久99亚洲综合精品首页| 秋霞人成在线观看免费视频| 久久亚洲精品无码VA大香大香| 中文字幕乱码免费视频| 亚洲国产欧洲综合997久久| 亚洲国产精品毛片av不卡在线| 黄 色一级 成 人网站免费| 亚洲影院在线观看| 女人张开腿等男人桶免费视频| 免费激情网站国产高清第一页| 亚洲精品午夜无码电影网| 亚洲一区二区三区免费视频| 亚洲经典千人经典日产| 成人午夜亚洲精品无码网站| 69精品免费视频| 亚洲成a人片在线观看无码专区| 中文字幕在线免费| 亚洲av日韩综合一区二区三区| 亚洲精品无码久久千人斩| 18禁网站免费无遮挡无码中文 | 中文字幕亚洲综合久久| 狠狠久久永久免费观看| 两个人看的www免费高清|