API / Apache Velocity Interview questions
Why is Velocity described as a "template engine" rather than a full programming language?
Velocity is deliberately restricted to a small set of constructs: references to display data, directives for basic control flow (#if, #foreach), and macros for reuse. It has no way to define classes, throw or catch exceptions, open files, or perform I/O from within a template.
That narrow surface area is a design choice, not a technical limitation of the parser. The intent is that a template can only display and lightly arrange data that Java code has already prepared, never compute or fetch it. This keeps the "what to show" layer separate from the "how to get the data" layer, which is the core idea behind the MVC pattern that frameworks like Struts and Turbine built around Velocity.
Anything that looks like real logic, validation, database access, formatting rules, belongs in Java (or a helper object exposed to the context), not in the .vm file.
More Related questions...