Scala 3 Module 1
Start here: Scala 3.9 LTS on the JVM interview questions
Interview questions on “Start here: Scala 3.9 LTS on the JVM”: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What is the difference between Scala Next and Scala LTS, and which would you use for a new library?
Answered in the lesson What Scala 3 is and where it runs in 2026
-
Fresher
Why does Scala need a JDK, and which version does Scala 3.9 need?
Answered in the lesson Install Scala 3.9, a JDK and an editor
-
Fresher
What does @main do in Scala 3, and how is it different from writing def main(args: Array[String]) yourself?
Answered in the lesson First programs: scala run, scripts and the REPL
-
Fresher to mid
What does -Werror do, and why do teams turn it on in CI?
Answered in the lesson Read Scala compiler errors and warnings
-
Fresher
What is the difference between == and eq in Scala, and how does it compare with Java and Python?
Answered in the lesson Scala 3 for Java and Python developers
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
Your team maintains an internal library used by services on Scala 3.3.8 and on 3.9.0. A developer wants to publish the next release compiled with 3.10.0 to use a new language feature. What do you decide, and how do you roll it out?
- What it tests
- The one-way compatibility rule between Scala 3 minor versions, why libraries publish with an LTS version, and planning a version move for the users of a library.
- First step
- Write the rule down: Scala 3.b reads the output of 3.a only if b is at least a. A 3.10.0 build would shut out every 3.3 and 3.9 service, and even a 3.9.0 build shuts out the 3.3 ones. So list the library's users by Scala version before choosing anything.
- Follow-ups
-
- The new feature saves real code. How could you use it without breaking the 3.3 users?
- When can the library drop 3.3?
- Would you publish two builds of the same release?
From the lesson What Scala 3 is and where it runs in 2026
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
A company writes Spark 4.2 jobs and back-end services in Scala and wants one shared module of domain code. Why can't both sides simply use Scala 3.9, and how would you structure the shared module?
- What it tests
- Knowing that Spark's Scala API fixes the jobs' Scala version, how Scala 2.13 and Scala 3 can use each other's libraries, and the cost of cross-building.
- First step
- Start from Spark's documentation: an application using the Scala API must use the Scala version Spark was compiled for, and Spark 4.2.0 runs on Scala 2.13. So the jobs compile with 2.13 and the services with 3.9, and the shared module must be readable from both.
- Follow-ups
-
- What does cross-building the shared module mean in practice?
- Which Scala 3 features must the shared code avoid?
- What changes when Spark publishes a Scala 3 build?
From the lesson What Scala 3 is and where it runs in 2026
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to senior
A service moved from Scala 3.3.8 to 3.9.0. It still compiles and passes its tests in CI, but the container that runs it now fails at start-up with UnsupportedClassVersionError. Explain the error and how you would fix it, with the trade-offs.
- What it tests
- Class-file versions and the JDK minimum of Scala 3.8 and later, telling the build JDK from the runtime JDK, and choosing between moving the runtime and staying on 3.3 LTS.
- First step
- Read the two numbers in the message: the class-file version of the class and the highest one the JVM recognises. Scala 3.9 writes version 61, Java 17's, and a runtime that stops at 55 is JDK 11. So the build ran on a newer JDK than the container does.
- Follow-ups
-
- Why did CI not catch it?
- When would you stay on 3.3 LTS instead?
- How do you make the build and the runtime agree for good?
From the lesson Install Scala 3.9, a JDK and an editor
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
On a teammate's laptop,
java -versionprints 25, but the version report run withscala runprints Java 21, and the run still shows the JDK 25 warning lines. Explain what is happening, and how you would make every developer and CI run the same JDK.- What it tests
- Knowing that the scala launcher follows PATH while the program follows JAVA_HOME, where the warnings come from, and pinning the JDK and the Scala version per project.
- First step
- Two JVMs are at work. The warnings come from the launcher, which runs on the first java on PATH, JDK 25, and the program runs on the JDK of JAVA_HOME, which must point at JDK 21 there. Check
java -version,echo $JAVA_HOMEand the report side by side. - Follow-ups
-
- Is it a problem that the two JDKs differ?
- How would you pin the JDK for the project?
- What else must match between laptops and CI?
From the lesson Install Scala 3.9, a JDK and an editor
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Your CI runs
scala testandscala runin containers without internet access. After the image was rebuilt, the jobs fail withError getting Bloop class path. Explain the cause and give two fixes, with their costs.- What it tests
- Knowing that Scala CLI downloads the Bloop compile server, compilers and libraries on first use, what --server=false changes, and how to prepare a build image that works offline.
- First step
- Read the lines before the error: Scala CLI tried to download Bloop from Maven Central and every attempt failed. The old image must have had it in its cache. So ask what the rebuilt image lacks: Bloop, and perhaps the compiler and the libraries as well.
- Follow-ups
-
- How do you warm the image's cache while it is built?
- What changes for the compile times with --server=false?
- How do you make sure no Bloop process outlives a job?
From the lesson First programs: scala run, scripts and the REPL
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
You are writing a small command-line tool in Scala 3 that other scripts call, for example
split 17725 3. Design its entry point: an @main method with typed parameters, or your own argument handling? Cover error messages, exit status and testing.- What it tests
- Knowing what the generated main does with bad, missing and extra arguments, keeping parsing apart from the logic, and choosing exit statuses that callers can rely on.
- First step
- Start from what the generated main does on Scala 3.9.0: it converts each argument, prints Illegal command line on a bad or missing one, ignores extra ones, and ends with status 0. A tool that scripts call needs a non-zero status on a mistake, so that behaviour alone is not enough.
- Follow-ups
-
- How would you test the argument handling without starting a JVM per case?
- Which exit statuses would you use?
- When is the plain @main form good enough?
From the lesson First programs: scala run, scripts and the REPL
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A payments service matches on an enum of payment methods. Someone added a new method, the build printed one warning, and production then threw MatchError for the new method. How do you fix it, and how do you stop this kind of bug for good?
- What it tests
- Exhaustivity checking on enums and sealed types, why a warning is not enough, -Werror in CI, and avoiding wildcard cases that hide new values.
- First step
- Read the warning the build printed: E029, match may not be exhaustive, it would fail on the new value. The compiler knew and the build did not stop. So fix every match it names first, then make such warnings fail the build.
- Follow-ups
-
- Why not just add case _ => to every match?
- How do you roll out -Werror in a codebase that has 300 warnings?
- What if the match is over a type the compiler cannot check, such as a String?
From the lesson Read Scala compiler errors and warnings
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A build fails with "No given instance of type Ordering[B] was found for parameter ord of method sorted" on a list of Order case classes. Walk through how you read the message, the ways to fix it, and which one you would choose.
- What it tests
- Reading a long E172 message from its first line, knowing what a given instance and a using parameter are, and choosing between sortBy, a natural order and named orderings.
- First step
- Read the first line first: sorted has a using parameter of type Ordering, and no given Ordering for Order exists. The rest of the message is the compiler's search. So decide how orders should be compared before writing any fix.
- Follow-ups
-
- Where should a given Ordering live, and why there?
- Why did the suggested import not help?
- What changes if orders must be sorted two different ways?
From the lesson Read Scala compiler errors and warnings
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to senior
A Java library's lookup method returns null when a key is missing, and your Scala code calls it in 30 places. How do you make the Scala side null-safe, where do you convert, and what about values that arrive as Optional or as Java collections?
- What it tests
- Handling nulls once at the boundary with Option, converting Optional and Java collections with the scala.jdk converters, and knowing what the compiler can and cannot check.
- First step
- Find the boundary, the one place where the Java value enters your code. Wrap the call there in a small Scala method that returns an Option, built with Option(javaCall(key)), and let the 30 call sites use that method instead of the Java one.
- Follow-ups
-
- What about a Java method that returns Optional?
- And a java.util.List that may contain nulls?
- Can the compiler help you find the missing checks?
From the lesson Scala 3 for Java and Python developers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
You port a Java service method, public Optional<User> findUser(String id) throws IOException, to Scala. Both Java and Scala code will call it. How do you design its signature for Scala callers, and what do Java callers get?
- What it tests
- Option and Optional at an API boundary, @throws for Java callers, and choosing between exceptions and an Either in a Scala API.
- First step
- Separate the two audiences. Scala callers want Option[User] and get nothing from a throws clause, because Scala does not check exceptions; Java callers want Optional<User> and a declared IOException. One method rarely serves both well, so design for Scala and add a thin Java-facing method.
- Follow-ups
-
- Would you return Either instead of throwing?
- How do Java callers see a Scala Option?
- What does @throws change, and what does it not?
From the lesson Scala 3 for Java and Python developers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes