Scala (programming Language) - Examples - "Hello World" Example

"Hello World" Example

Here is the classic Hello World program written in Scala:

object HelloWorld extends App { println("Hello, World!") }

Unlike the stand-alone Hello World application for Java, there is no class declaration and nothing is declared to be static; a singleton object created with the object keyword is used instead.

With the program saved in a file named HelloWorld.scala, it can be compiled from the command line:

$ scalac HelloWorld.scala

To run it:

$ scala HelloWorld

This is analogous to the process for compiling and running Java code. Indeed, Scala's compilation and execution model is identical to that of Java, making it compatible with Java build tools such as Ant.

A shorter version of the "Hello World" Scala program is:

println("Hello, World!")

Saved in a file named HelloWorld2.scala, this can be run as a script without prior compilation using:

$ scala HelloWorld2.scala

Commands can also be fed directly into the Scala interpreter, using the option -e:

$ scala -e 'println("Hello, World!")'

Read more about this topic:  Scala (programming Language), Examples

Famous quotes containing the word world:

    We try to go back. You know I’ll probably die just a few miles from where I drew my first breath. That would have seemed like a horrible prospect to me, back when I was young and ambitious and gonna set the world on fire. But there’s comfort in knowing you’re gonna go full circle, end up where you started out. I’ve said before that I want to live my last days where folks know when you’re sick and care when you die.
    Lyndon Baines Johnson (1908–1973)