This article  contains Scala Hello World Example with details explanation of each elements.

NOTE: Make sure that your operating system PATH variable contains SCALA_HOME path. To make sure,

Go To console & Type : scala

Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.1).
Type in expressions for evaluation. Or try :help.

HelloWorld.scala

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Scala Hello World Example")
  }
}

object: object is used to create singleton class, scala does not support static keyword

def : function or definition

main : method name

args : Array[String] means array of String and variable name is args

Unit : Function is return nothing (void)

Compile scala code:

scalac HelloWorld.scala

scalac is scala compiler. It will generate HelloWorld.class file in current working directory.

Run scala code:

scala HelloWorld

Output:

Scala Hello World Example

References

Scala documentation

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *