← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 4 of 8

Running Scripts with scala

You can run a Scala file straight from the terminal without any extra steps. It is like pressing play on a saved song instead of building the speaker first.
Syntax
scala
scala FileName.scala

Running Scripts with scala

The scala command can directly run a .scala file without a separate compile step, making it convenient for quick scripts, though it compiles internally before running.

For larger projects, scalac compiles to .class files ahead of time, which then run faster on repeat execution. Judge0 compiles your submitted code with scalac before running it.

Note: scala file.scala compiles and runs a script in one command, ideal for quick, one-off programs.

Example: Running Scripts with scala

markup
object Main extends App {
  println("This program was compiled and run via the scala toolchain")
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running scala Hello on a file name with no .scala extension, so the file is not found.
  2. Defining a main method without an object, so the script has no entry point to run.
  3. Expecting the script to be fast on repeated runs, when it recompiles each time; use scalac for a compiled build.
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.