Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Scala is a statically typed language created by Martin Odersky and first released in 2004 that fuses object-oriented and functional programming on the Java Virtual Machine. Its name is short for "scalable language," and it lets you combine immutable values, pattern matching, and higher-order functions with full access to Java's libraries. It became the language behind big-data tools such as Apache Spark and remains popular in data engineering, fintech, and backend services where type safety and JVM performance matter. Scala 3 modernised the syntax while keeping that dual paradigm. On XCODX your code is compiled and then run on the JVM using the standard library, so expect a brief startup pause before output appears.
object Main {
def main(args: Array[String]): Unit = {
val nums = List(1, 2, 3, 4, 5, 6)
val evens = nums.filter(_ % 2 == 0)
val total = nums.sum
println(s"Numbers: ${nums.mkString(", ")}")
println(s"Evens: ${evens.mkString(", ")}")
println(s"Sum: $total")
val label = total match {
case t if t > 20 => "big"
case _ => "small"
}
println(s"The sum is $label")
}
}
Scala's strengths are an expressive static type system, a concise blend of object-oriented and functional style, and direct reuse of the entire Java ecosystem, which suits data pipelines, streaming systems, and large backend codebases that must stay correct as they change. Choose it when you are working with Spark or Akka, or when a team wants functional guarantees without leaving the JVM. It is a heavier choice for small scripts and quick automation, where its compile step and JVM startup make lighter tools like Python or a shell script more convenient.
No. The sandbox compiles against the Scala standard library only, with no sbt or Maven build and no network to download dependencies, so frameworks like Spark, Akka, and Cats are unavailable. You can still use everything under scala.* and the java.* classes that ship with the JVM. Use sbt on your own machine for projects that need external libraries.
Import scala.io.StdIn and call readLine() for a whole line, or helpers such as readInt() and readDouble() to parse as you read. In XCODX you type into the live terminal or the Stdin Box and press Enter, and Ctrl+D closes the stream. readLine() returns null at end of input, so guard against that inside loops.
You need one entry point. The classic form is object Main { def main(args: Array[String]): Unit = { ... } }, and Scala 3 also lets you write @main def run() = ... at the top level. Either works in the sandbox; the source is compiled first and then executed, which is why there is a short pause before output.
The delay is JVM startup plus compilation, not your logic. XCODX compiles the source and boots a fresh Java Virtual Machine on every run, which adds a moment before the first line prints. Once running the compiled bytecode executes quickly, so the pause is fixed overhead rather than a sign of a problem.
Both run on the JVM and interoperate, but Scala adds functional programming, immutable-by-default values, pattern matching, and much less boilerplate, while Java is more verbose and imperative by tradition. Scala code can call Java libraries directly, which is why data tools often build on it. Java is still simpler to learn and has a larger hiring pool.
Scala stays in active use for data engineering, streaming, and fintech backends where type safety and JVM performance are valued, and Scala 3 smoothed much of the older syntax. It is a bigger language to learn than Kotlin or Python, so it rewards developers who want deep functional-plus-OO expressiveness on the JVM. For pure Android or quick scripting, other JVM options are lighter.
Main.scalatext/x-scalaStdIn.readLine()object Main extends App {
println("Hello from Scala!")
println("Welcome to XCODX Online Compiler!")
val message = "Scala is powerful!"
println(message)
}
Building the jar produces a duplicate-manifest warning from java.util.jar. It is filtered from the output pane.