Scrivio Interview library
LeadershipAdvanced7 min read · updated 12 November 2026

Your company runs services on JDK 8, 11, 17 and 21. You want to make UTF-8 the guaranteed encoding everywhere. What is your plan and what risks do you look for?

My plan has two tracks. In the short term, JDK 18 and later already default to UTF-8, so the JDK 21 services are covered, and we align the JDK 8, 11 and 17 services by starting them with -Dfile.encoding=UTF-8 through the shared platform configuration. In the long term, we fix the code itself: static analysis such as forbidden-apis finds every API that relies on the default charset, and we change each call to pass an explicit charset. We watch for legacy data in other encodings, Windows consoles and properties files, test with non-ASCII data, and treat COMPAT on newer JDKs as a temporary fallback only.

Background to this question

Mixed JDK fleets are normal in large companies, and encoding is one of the places where the versions behave differently, because JDK 18 changed the default charset. A leadership answer here is not just which flag to set. It is a plan that gets every service to the same guarantee without breaking the ones that silently depend on the old behaviour, with a way to know we are done. In this answer, we will recap what differs across the four versions, lay out the short-term alignment, the code fixes and how to find them, go through the risks to look for, and finish with testing and communication.

1A Quick Recap: What Differs Across the Versions

Many Java APIs convert between bytes and characters without naming a charset: new String(bytes), getBytes(), FileReader, FileWriter, InputStreamReader, PrintStream and others. They all use the default charset. On JDK 8, 11 and 17, that default comes from the operating system and locale at startup, usually UTF-8 on Linux containers but often a legacy code page on Windows or on hosts with an unusual LANG setting. Since JDK 18, JEP 400 makes it UTF-8 everywhere, regardless of the operating system.

So today our JDK 21 services behave consistently, while the older ones behave according to the machine. Some APIs were already consistent: the java.nio.file.Files methods default to UTF-8 on every version, and javac reads source files in UTF-8 by default only since JDK 18.

Default charset by JDK version
JDKDefault charsetHow to align it
8from OS and locale-Dfile.encoding=UTF-8, then fix code
11from OS and locale-Dfile.encoding=UTF-8, then fix code
17from OS and locale (native.encoding shows it)-Dfile.encoding=UTF-8, then fix code
21UTF-8 (JEP 400, since 18)already aligned; COMPAT only as a fallback
Files.* methods default to UTF-8 on all four versions.

2Short Term: Align the Older JDKs With a Flag

The quickest way to make the old services consistent is to start them with -Dfile.encoding=UTF-8. On JDK 8 to 17 this sets the default charset for the APIs above. It is not officially documented as supported on those versions, but it is widely used and works for the common APIs. It does not change everything: file names use sun.jnu.encoding, and console output on Windows follows the console's code page.

We roll this out through the shared platform configuration, the base container image, a common JAVA_TOOL_OPTIONS or the service template, not through each team's start script. A canary group goes first, because a service that has been reading windows-1252 files by accident will start misreading them when the default changes. That is exactly the kind of hidden dependency we want to find early, with a small blast radius.

3Long Term: Fix the Code With Static Analysis

The flag is a safety net; the guarantee comes from code that names its charset, because then the result no longer depends on any flag or version. Finding the calls by hand in hundreds of repositories is hopeless, so we use static analysis. The forbidden-apis tool, available as a Maven and Gradle plugin, has a signature set for JDK APIs that depend on the default charset or locale, and Error Prone has a DefaultCharset check. We enable it in the shared build configuration, first as a report, then as a build failure for new code.

Java
// Flagged by the checks: depends on the default charset
String s = new String(bytes);
Reader r = new FileReader(file);
byte[] b = text.getBytes();
// Fixed: explicit charset, identical on every JDK
String s2 = new String(bytes, StandardCharsets.UTF_8);
Reader r2 = Files.newBufferedReader(path, StandardCharsets.UTF_8); // works on JDK 8 too
byte[] b2 = text.getBytes(StandardCharsets.UTF_8);

Notice that the fixes are mechanical in most places, so teams can work through the report quickly, and many changes can be prepared automatically with a refactoring recipe. The places that are not mechanical, where the right charset is not UTF-8, are exactly the risky ones we look at next.

4Risks to Look For

The first risk is legacy data. Files, message queues and database columns written years ago by services running on Windows or on hosts with another locale may contain windows-1252 or ISO-8859-1 bytes. Reading them as UTF-8 silently produces replacement characters. For each such source we either convert the data once, or read it with its real charset explicitly, documented in the code. A strict CharsetDecoder with CodingErrorAction.REPORT in a dry run tells us which files are not valid UTF-8.

The second is console output on Windows, which follows the console's code page, not the default charset; JDK 19 added the stdout.encoding property for it. Tools that parse the output of Windows-hosted jobs may see different bytes. The third is properties files: ResourceBundle reads them as UTF-8 since JDK 9, with an ISO-8859-1 fallback, but Properties.load(InputStream) still reads ISO-8859-1 on every version, so the same file can be read differently by two APIs. We standardise on UTF-8 files and load them with Properties.load(Reader) using an explicit UTF-8 reader. The fourth is databases and drivers: the connection's character set, such as utf8mb4 for MySQL, must be UTF-8 as well, or the database converts text on its way in.

Step throughRollout plan
  1. Inventory services by JDK and OSwho relies on the default today
  2. Canary -Dfile.encoding=UTF-8 on JDK 8 to 17via the platform image
  3. Problems found?
    YesFix the source explicitly, then widenNoWiden rollout in stages
  4. Static checks: report, then fail new codeforbidden-apis or Error Prone
  5. Non-ASCII data in CI and contract tests
  6. Done when no charset-less calls remainflag no longer needed

6 steps in order. Play them, or step through them one at a time.

5Testing and Communication

Encoding bugs hide behind ASCII test data, so the plan includes test data that would expose them: accented Latin letters, CJK text and emoji in names, addresses and free-text fields. We add them to unit tests that read and write files, and, most importantly, to contract tests between services, because many encoding bugs happen at the boundary, one service writing and another reading. Running the CI suite once with an unusual default, for example -Dfile.encoding=ISO-8859-1 on an old JDK, shows which code still depends on the default.

Finally, we communicate. Teams need a short note explaining why the change is happening, what the flag does on their JDK, how to read the static analysis report and what to do with legacy data. For services on JDK 18 and later that hit a problem, the -Dfile.encoding=COMPAT option restores the old platform default, but we present it as a temporary fallback with a ticket to remove it, not as a solution, otherwise it quietly becomes permanent. We track progress with one number per service: the count of remaining charset-less calls, which should reach zero.

6Follow-up questions

How do you handle a legacy file format that really is windows-1252?

Read it with Charset.forName("windows-1252") explicitly, in one adapter class with a comment explaining why, and convert to UTF-8 at the boundary so the rest of the system only sees Strings or UTF-8 bytes. The static check then passes because the charset is named.

What about source files with non-ASCII characters?

javac defaults to UTF-8 only since JDK 18, so for older JDKs we set project.build.sourceEncoding to UTF-8 in Maven or the encoding option in Gradle. Otherwise string literals with accented letters compile differently on different build agents.

7Conclusion

In this answer, we made UTF-8 the guaranteed encoding in two tracks: a short-term flag, -Dfile.encoding=UTF-8, rolled out on canaries through platform configuration to align JDK 8, 11 and 17 with the UTF-8 default that JDK 18 and later already have, and a long-term code fix driven by forbidden-apis or Error Prone so that every conversion names its charset. We looked for the real risks, legacy data in other encodings, Windows console output, properties files read by Properties.load and database connection charsets, tested with non-ASCII data in CI and contract tests, and communicated COMPAT as a temporary fallback only.

What to say in the interviewAbout 100 seconds aloud

Open with

I would run it in two tracks. The JDK 21 services already default to UTF-8 because of JEP 400 in JDK 18, so the gap is 8, 11 and 17, where the default comes from the OS and locale.

Then, if they want more

Short term, I would set file.encoding to UTF-8 for those through the platform base image or common JVM options, rolled out on canaries first, because any service that has been reading windows-1252 files by accident will start misreading them, and I want to find those with a small blast radius. Long term, the flag is just a safety net.

The real guarantee is code that names its charset, so I would turn on forbidden-apis or Error Prone's DefaultCharset check in the shared build, first as a report, then failing new code, and have teams fix the calls, which are mostly mechanical.

The risks I would look for are legacy files, queues and database columns written in another encoding, which I would detect with a strict decoder in a dry run and then either convert or read with their real charset explicitly; Windows console output, which follows the console code page; properties files, because ResourceBundle reads UTF-8 since JDK 9 but Properties.load with an InputStream is still ISO-8859-1; and database connection charsets.

I would add accented, CJK and emoji data to CI and especially to contract tests between services. And I would communicate clearly, with COMPAT on newer JDKs offered only as a temporary fallback with a ticket to remove it, and track the remaining charset-less calls per service until they reach zero.

About this answer

Last updated
12 November 2026
Versions it names
Java 18, Java 8, Java 21, Java 19
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your company runs services on JDK 8, 11, 17 and 21. You want to make UTF-8 the...": https://scrivio-interview-library.netlify.app/java/strings/3be9807ea5/