API / Apache Velocity Interview questions
When would you choose a Velocimacro over a Java-side helper method?
A Velocimacro makes sense when the reusable piece is fundamentally presentation: repeated markup structure, formatting layout, or a small conditional block that a template author needs to control without touching Java code, like a standard way to render a labeled form field or a pagination widget.
A Java-side helper (exposed into the context as a tool object) is the better choice when the logic is computational, involves data access, needs unit tests, or benefits from IDE support like debugging and static typing, such as currency conversion, permission checks, or date formatting.
A rough rule: if what varies between calls is mostly markup and structure, use a Velocimacro; if what varies is a calculation or a decision, compute it in Java and hand the template a ready-to-display result.
More Related questions...