Running your first Scala program.

Category : Scala | Sub Category : Scala Programs | By Prasad Bonam Last updated: 2023-10-20 14:12:12 Viewed : 544


To run your first Scala program, you will need to follow these simple steps:

  1. Install Scala: If you have not already, you need to install Scala on your system. You can refer to the previous instructions for installing Scala on your operating system.

  2. Choose a Text Editor or IDE: You can use any text editor or IDE that supports Scala. Some popular choices include IntelliJ IDEA, Visual Studio Code with Scala Metals, or Eclipse with the Scala IDE plugin.

  3. Write Your First Scala Program: Open your preferred text editor or IDE and create a new file with a .scala extension. You can start with a simple "Hello, World!" program:

scala
object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } }
  1. Save the File: Save the file with a .scala extension, for example, HelloWorld.scala.

  2. Run the Scala Program:

    • If you are using an IDE, you can typically run the program directly from the IDE by clicking the run button.
    • If you are using a text editor, you can run the Scala program using the Scala interpreter or the Scala compiler. Here is how to do it using the Scala compiler:
      • Open your terminal or command prompt.
      • Navigate to the directory where you saved the HelloWorld.scala file.
      • Run the following command to compile the program:
        scalac HelloWorld.scala
      • This will generate a HelloWorld.class file.
      • To run the program, use the following command:
        scala HelloWorld
      • You should see the output Hello, World! in the terminal.

Congratulations! You have successfully run your first Scala program. Now you can continue exploring the language and its features to build more complex applications.

Search
Related Articles

Leave a Comment: