Scala online IDE & code editor for technical interviews

Running Scala 2.13 – IntelliSense is not available

Experience the Scala IDE yourself

See just how easy and intuitive CoderPad Interview is to use below.

Launch the environment

Guidelines to use Scala in this online IDE

You should define an object named Solution that extends App, like so:

object Solution extends App {
  for (i <- 0 until 5) println("Hello, world!")
}Code language: Scala (scala)

Alternatively, you can forego using the App trait helper and define main yourself:

object Solution {
  def main(args: Array[String]) = {
    println("Hello, world!")
  }
}Code language: Scala (scala)

We include the Scala testing libraries ScalaCheck and ScalaTest for your convenience. Here’s a quick example of using ScalaTest driven by ScalaCheck generators:

import org.scalatest.freespec.AnyFreeSpec

class SetSpec extends AnyFreeSpec {

  "A Set" - {
    "when empty" - {
      "should have size 0" in {
        assert(Set.empty.size === 0)
      }

      "should produce NoSuchElementException when head is invoked" in {
        assertThrows[NoSuchElementException] {
          Set.empty.head
        }
      }
    }
  }
}

object Solution extends App {
  new SetSpec().execute()
}Code language: Scala (scala)

Here’s a quick rundown of the Scala libraries we have installed:

libraryDependencies ++= Seq (
  "com.chuusai"     %% "shapeless"                    % "2.3.7",
  "org.scalacheck"  %% "scalacheck"                   % "1.15.4",
  "org.scalactic"   %% "scalactic"                    % "3.2.10",
  "org.scalamock"   %% "scalamock"                    % "5.1.0",
  "org.scalatest"   %% "scalatest"                    % "3.2.10",
  "org.scalaz"      %% "scalaz-core"                  % "7.3.5",
  "org.typelevel"   %% "cats-core"                    % "2.6.1"
)Code language: Scala (scala)

Additionally, these Java libraries are available. Simply import and use as desired:

  • json-simple for parsing/encoding JSON.The google code project page has some useful examples.
  • guava provides immutable collections and other handy utility classes.
  • junit, the gold standard for testing in Java, but quite usable in Scala as well.import org.junit.Test
import org.junit.Test
import org.junit.runner.JUnitCore
import org.junit.Assert

class TestClass {
  @Test def testNoop() = {
    Assert.assertTrue(true)
  }
}

object Solution {
  def main(args: Array[String]) = {
    JUnitCore.main("TestClass")
  }
}Code language: Scala (scala)
  • jMock, a library to assist with mocking in Java. The homepage has some useful examples, and can be adapted for Scala, too.

Need a better way to interview candidates? Give CoderPad a try.