Monday, August 13, 2018

Scala Hello World Example With Extending App trait

Guys/Girls I am using Eclipse IDE for Scala for development

You can easily download this from below URL

http://scala-ide.org/download/current.html

Now lets start with our first example.As usual it Hello World program.

Please follow below steps to create and execute first class

Step:1)GO to file =>New=>Select "Scala Class"

Step:2)Give name as HelloWorld.scala

Step:3) Inside Class use method println to write hello world.

code will look like

class HelloWorldWithObject {
println("Hello World");
}

Step:4)Extend this class with App trait

NOte:What IS App trait,Below is small documentation of App
scala.App
The App trait can be used to quickly turn objects into executable programs. Here is an example:

object Main extends App {
  Console.println("Hello World: " + (args mkString ", "))
}


Here, object Main inherits the main method of App.

args returns the current command line arguments as an array.

Step:5)Complete class will look like

package com.sagar.basic

class HelloWordlWithApp extends App {
println("Hello World");

}

Step:6) Right click inside class and run it as scala application it will print below output:

Hello World

No comments:

Post a Comment

How to check whether operating system is 64 bit or 32bit?

What is 32 and 64 bit operating system? The terms 32-bit and 64-bit refer to the way a computer's processor that is CPU, handles info...