Scala - Main (Top-Level Objects)

Card Puncher Data Processing

About

In Scala, the main or entry point method is defined in an object.

An object can be made executable by either:

Two way

App

object extends the type App trait

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

If that object extends trait App, 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.

Main

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, World!")
  }
}





Discover More
Card Puncher Data Processing
Scala - Getting Started (Hello World)

Getting started page with an HelloWorld example and some documentation. Create a main HelloWorld object: Run it interactively: Compile it: Run the compile code: In a maven project,...
Card Puncher Data Processing
Scala - Object (Singleton)

Object in Scala are like classes, but for every object definition there is only one single instance (See ). It is not possible to create instances of objects using new, instead you can just access the...
Scala Sbt Based Project
Scala - SBT (Builder)

Sbt is a build tool for Scala You can start the Scala interpreter inside sbt using the console task. If your project has an object with a main method (or an object extending the trait App),...
Card Puncher Data Processing
Scala - Scala Command (Execute Bytecode)

The scala command executes the generated bytecode. scala allows us to specify command options, such as the -classpath (alias -cp) option: The argument of the scala command has to be a top-level object....



Share this page:
Follow us:
Task Runner