Status: String Templates were introduced as a preview feature in Java 21 (JEP 430) and continued as a second preview in Java 22 (JEP 459). They were withdrawn in Java 23 because the design didn't satisfy its own goals around safe-by-default interpolation and editor-friendly syntax. The feature is being redesigned. You can't use the syntax in this lesson in production on Java 23 or later. We're teaching it anyway because interview questions about "what's new in Java" still cover it, the design trade-offs are worth understanding, and the eventual replacement is likely to keep the same shape (template + processor produces value). Treat the code in this lesson as historical and instructive, not as a tool to use today.
String templates were Java's answer to a problem every other modern language solved a decade ago: how do you splice variables into a string without + noise, String.format mismatches, or unsafe string concatenation that creates a SQL injection vulnerability? The proposed answer was to combine a template (the string with embedded expressions) with a processor (a small class that decides what the template means). This lesson walks through the model, the three built-in processors, and the main feature, custom processors that escape SQL and HTML automatically. We'll also discuss why the feature was pulled and what to use today.