Scala Application: In Scala, App is a trait defined in scala package like “scala.App”. It defines main method. If an Object or a Class extends this trait, then they will become as Scala Executable programs automatically because they will inherit main method from Application. The main advantage of using App is that we don’t need to write main method. The main drawback of using App is that we should use same name “args” to refer command line argument because scala.App’s main() method uses this name. Example:- Without Scala App:
object MyApp {
def main( args: Array[String]){
println("Hello World!")
}
}
With Scala App:
object MyApp extends App{
println("Hello World!")
}
If we observe above two examples, in second example we have not defined main method because we have inherited from Scala App(Application). Before Scala 2.9, we have scala.Application trait. But it is deprecated by scala.App since Scala 2.9 version.