🌐
Oracle
docs.oracle.com β€Ί en β€Ί java β€Ί javase β€Ί 21 β€Ί language β€Ί string-templates.html
4 String Templates
January 16, 2025 - String templates complement Java's existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results. An embedded expression is a Java expression except it has additional syntax to differentiate it from the literal ...
🌐
HappyCoders
happycoders.eu β€Ί home β€Ί java β€Ί string templates in java
String Templates in Java
2 weeks ago - Mastering Java 25 – All New Features Since Java 21 Β· 2 days, on-site or virtual.View training Β· Update: On April 5, 2024, Gavin Bierman announced that String Templates will not be released in the form described here. There is agreement that the design needs to be changed, but there is no consensus on how it should be changed.
Discussions

String Templates. Then What?
I'm aware that the String Template JEP is still in the early phase. You are aware that they have been pulled completely for now? More on reddit.com
🌐 r/java
64
21
February 9, 2025
java - Why is String template not available - Stack Overflow
JDK 23 Release Notes: "String Templates were first previewed in JDK 21 (JEP 430) and re-previewed in JDK 22 (JEP 459). After feedback and extensive discussion, we concluded that the feature is unsuitable in its current form. There is no consensus on what a better design will be, therefore we have withdrawn the feature for now, and JDK 23 will not include it." :-( ... Are you using Maven or Gradle? Have you got something like javaToolchain... More on stackoverflow.com
🌐 stackoverflow.com
What Happened to Java's String Templates? Inside Java Newscast
Honestly, this whole thing with string templates in java feels like a paranoia. Security? Validation? The hell are they smokin there? Why are they trying to solve world hunger with it? Just give people the damn interpolation like all normal human beings have other languages that's all we want. More on reddit.com
🌐 r/java
122
66
June 20, 2024
There will be no String Template in JDK 23.
wow. It's interesting that Brian Goetz recently said he was ready to finalize the feature and move on, and all the complaints were nothing they hadn't anticipated and discussed extensively. They had the JEP submitted to finalize this for Java 22 and they held off to a second unchanged preview, and then were going to finalize for Java 23, and now, even Goetz is ready to move the whole thing back to a complete redesign. As a Java dev I'd rather get this later with a better design than earlier with a less perfect design. It is interesting how close the existing design was to being finalized. The preview system works :) More on reddit.com
🌐 r/java
131
122
April 6, 2024
🌐
Pcsalt
pcsalt.com β€Ί java β€Ί java 25 β€” string templates & flexible constructor bodies
Java 25 β€” String Templates & Flexible Constructor Bodies
January 15, 2026 - Java 25 finalizes string templates with the STR processor and flexible constructor bodies β€” two features that simplify everyday Java code.
🌐
Reddit
reddit.com β€Ί r/java β€Ί string templates. then what?
r/java on Reddit: String Templates. Then What?
February 9, 2025 -

It's weekend, so...

I'm aware that the String Template JEP is still in the early phase. But I'm excited about the future it will bring. That is, not a mere convenient String.format(), but something far more powerful that can be used to create injection-safe higher-level objects.

Hypothetically, I can imagine JDBC API being changed to accept StringTemplate, safely:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  var results = connection.query(
      // Evaluates to a StringTemplate
      // parameters passed through PreparedStatement
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """);
}

We would be able to create dynamic SQL almost as if they were the golden gold days' static SQL. And the SQL will be 100% injection-proof.

That's all good. What remains unclear to me though, is what to do with the results?

The JDBC ResultSet API is weakly typed, and needs the programmer to call results.getString("UserId"), results.getDate("BirthDay").toLocalDate() etc.

Honestly, the lack of static type safety doesn't bother me much. With or without static type safety, for any non-trivial SQL, I wouldn't trust the correctness of the SQL just because it compiles and all the types match. I will want to run the SQL against a hermetic DB in a functional test anyways, and verify that given the right input, it returns the right output. And when I do run it, the column name mismatch error is the easiest to detect.

But the ergonomics is still poor. Without a standard way to extract information out of ResultSet, I bet people will come up with weird ways to plumb these data, some are testable, and some not so much. And people may then just give up the testing because "it's too hard".

This seems a nice fit for named parameters. Java currently doesn't have it, but found this old thread where u/pron98 gave a nice "speculation". Guess what? 3 years later, it seems we are really really close. :-)

So imagine if I could define a record for this query:

record UserData(String userId, LocalDate birthDate, String email) {}

And then if JDBC supports binding with named parameters out of box, the above code would be super easy to extract data out of the ResultSet:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  List<UserData> userDataList = connection.query(
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """,
      UserData.class);
}

An alternative syntax could use lambda:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  List<UserData> userDataList = connection.query(
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """,
     (String userId, LocalDate birthDate, String email) ->
         new UserData() with {
             .userId = userId, .birthDate = birthDate, .email = email});
}

But:

  1. It's verbose

  2. The SQL can select 12 columns. Are we really gonna create things like Function12<A, B, C, ..., K, L> ?

And did I say I don't care much about static type safety? Well, I take it back partially. Here, if compiler can help me check that the 3 columns match in name with the proeprties in the UserData class, that'd at least help prevent regression through refactoring (someone renames the property without knowing it breaks the SQL).

I don't know of a precedent in the JDK that does such thing - to derive static type information from a compile-time string constant. But I suppose whatever we do, it'd be useful if JDK provides a standard API that parses SQL string template into a SQL AST. Then libraries, frameworks will have access to the SQL metadata like the column names being returned.

If a compile-time plugin like ErrorProne parses out the column names, it would be able to perform compile-time checking between the SQL and the record; whereas if the columns are determined at runtime (passed in as a List<String>), it will at least use reflection to construct the record.

So maybe it's time to discuss such things beyond the JEP? I mean, SQL is listed as a main use case behind the design. So might as well plan out for the complete programmer journey where writing the SQL is the first half of the journey?

Forgot to mention: I'm focused on SQL-first approach where you have a SQL and then try to operate it in Java code. There are of course O-R frameworks like JPA, Hibernate that are model-first but I haven't needed that kind of practice yet so I dunno.

What are your thoughts?

🌐
YouTube
youtube.com β€Ί watch
Java 25 String Templates Explained πŸ”₯ | Clean & Modern Way to Build Strings! #shorts - YouTube
Say goodbye to messy string concatenations! πŸš€Java 25 introduces String Templates β€” a modern way to build readable, clean, and elegant strings.Now you can em...
Published: October 24, 2025
🌐
Kodejava
kodejava.org β€Ί how-to-write-cleaner-code-with-string-templates-in-java
How to Write Cleaner Code with String Templates in Java - Learn Java by Examples
String templates allow you to define a string that contains placeholders for expressions. These placeholders are evaluated at runtime. In Java 25, this is done using the STR.""" syntax (or StringTemplate API).
🌐
Medium
medium.com β€Ί javarevisited β€Ί jdk-25-the-new-features-in-java-25-2366dc2f994f
JDK 25 β€” The New Features in Java 25 | by Harry | Javarevisited | Medium
August 13, 2025 - JDK 25 β€” The New Features in Java 25 Why Java 25 is not just another version number β€” and why you should care (even if you think you don’t) A few weeks ago, I opened up some old Java code from …
🌐
OpenJDK
openjdk.org β€Ί jeps β€Ί 465
JEP 465: String Templates (Third Preview)
January 9, 2024 - Ideally a string's template could be expressed directly in the code, as if annotating the string, and the Java runtime would apply template-specific rules to the string automatically. The result would be SQL statements with escaped quotes, HTML documents with no illegal entities, and boilerplate-free message localization.
Find elsewhere
🌐
Baeldung
baeldung.com β€Ί home β€Ί java β€Ί java string β€Ί string templates in java
String Templates in Java | Baeldung
July 7, 2025 - The same is followed for β€œβ€β€<some text>””” to distinguish between TextBlock and TextBlockTemplate. This distinction is important to Java because, even though in both cases it’s wrapped between double quotes(β€œβ€), a String template is of type java.lang.StringTemplate, an interface, and not the java.lang.String.
🌐
Java Almanac
javaalmanac.io β€Ί features β€Ί stringtemplates
String Templates (JEP 430, 459, 465, withdrawn) - javaalmanac.io
The FMT processor yields a String, but the RAW processor yields an object of the class StringTemplate. Here is a sandbox with these examples. Try adding a space before or after a format specifier. Also try reassigning item after the raw template was formed. Are the values updated? Should they be? import static java.util.FormatProcessor.FMT; import static java.lang.StringTemplate.RAW; public class TemplateProcessors { record Item(String description, int quantity, double price) {} public static void main(String[] args) { var item = new Item("Blackwell Toaster", 2, 29.95); String line = FMT."%-20s\{item.description()} | ]\{item.quantity()} | .2f\{item.price()}%n"; System.out.print(line); item = new Item("Zappa Microwave Oven", 1, 109.95); // TODO What happens if you add a space before or after %-20s?
🌐
Medium
medium.com β€Ί @harshal14ahire β€Ί java-25-a-complete-guide-to-the-new-features-35fc5e96412f
Java 25: A Complete Guide to the New Features | by Harshal Ahire | Medium
September 19, 2025 - The STR. is a template processor, and the expression within the curly braces \{...} is evaluated and its result is embedded directly into the string.
🌐
Medium
maffonso.medium.com β€Ί java-string-templates-simplifying-text-handling-1f36f864056e
Java String Templates: Simplifying Text Handling | by Mauricio Afonso | Medium
June 14, 2024 - To understand String Templates, we must start by talking about the structure of this feature. Template Processor + Template + Template Expressions ... mechanism that will process the text STR is a template processor defined in the Java Platform.
🌐
OpenJDK
openjdk.org β€Ί jeps β€Ί 430
JEP 430: String Templates (Preview)
September 17, 2021 - Enhance the Java programming language with string templates. String templates complement Java's existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results.
🌐
Codeline24
codeline24.com β€Ί java-string-templates
Java String Templates
The Java Virtual Machine (JVM) manages memory allocation and garbage collection in Java applications. It divides memory into several areas, ... With the introduction of string templates in Java 21 JEP 430, as a preview feature, proposed to be finalized with
🌐
JetBrains
blog.jetbrains.com β€Ί home β€Ί intellij idea β€Ί string templates in java – why should you care?
String Templates in Java - why should you care? - The JetBrains Blog
November 27, 2023 - TLDR; The existing String concatenation ... (a preview feature introduced in Java 21) greatly improves how we create strings in Java by merging constant strings with variable values....