Artificial Intelligence (AI) & Machine Learning Course for Managers

 Enroll Now

Scala

11 / 52
   

Scala - Assessment - Hello, World! Program

Let's write a "Hello world" program to learn how to compile and run a scala code.

INSTRUCTIONS
  • Switch the tab in Jupyter to console or Login to the CloudxLab web console.

  • Create a directory 'scala' and go inside it. Create a file hello_world.scala using the command "nano hello_world.scala". You can also use vim editor instead of nano. Type the code as displayed on the screen. Press "control o" to save the file and then press enter. Press "control x" to exit the nano editor.

    object HelloWorld {
        def main(args: Array[String]) {
            println("Hello, world!")
        } 
    }
  • To compile the code, type "scalac hello_world.scala" and press enter. You can see two class files HelloWorld$.class, HelloWorld.class. These .class files are generated bytecode which gets executed by JVM.

  • To run the code, type "scala HelloWorld". You can see that "Hello, world!" is printed on the screen.