API / Apache FreeMarker Interview questions
Why does FreeMarker use its own restricted expression language instead of plain Java?
FTL is deliberately less powerful than Java: it has no arbitrary class imports, no unrestricted method invocation, and no way to declare new Java types from inside a template. This is a design choice, not a limitation that slipped in by accident.
The intent is to enforce a clean separation between presentation and business logic. If templates could run full Java code, there would be nothing stopping business rules, database calls, or side effects from creeping into the view layer, which is exactly the coupling MVC-style separation tries to avoid. A restricted language also makes templates safe to hand to people who are not full-time programmers - designers, translators, or non-technical content editors - since there is a much smaller space of things that can go catastrophically wrong compared to a general-purpose scripting language embedded in the same role.
Anything a template genuinely needs from Java - a formatting helper, a lookup service - is exposed deliberately through the data model or a custom directive, which keeps the boundary explicit and reviewable rather than implicit.
More Related questions...