Monday, August 13, 2018

Scala Hello World Example With object class

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

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

2)Give name as HelloWorld.scala

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

code will look like

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

4)We need to run this class ut we can not run this class without main method so we are going to create one object having name hello

code for object is

object hello {

def main(args: Array[String]): Unit = {
var name = new HelloWorldWithObject();
}
}

5)The complete class will look like
package com.sagar.basic

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

def main(args: Array[String]): Unit = {
var name = new HelloWorldWithObject();
}
}

7)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...