API / Apache Velocity Interview questions
Why do we use Velocity instead of embedding logic in JSP?
Classic JSP allows scriptlets, raw Java code inside <% %> tags, directly on the page. That's convenient short-term but tends to blur the view and controller layers: business logic, data access, and formatting all end up mixed into the markup, which makes pages hard to test and hard to hand off to a non-Java page designer.
Velocity templates can't contain arbitrary Java at all, so that mixing is structurally prevented rather than just discouraged by convention. A designer can safely edit a .vm file without risking a compile error or accidentally changing application behavior.
JSP also compiles into a servlet per page and requires a servlet container to run, while Velocity can render templates from a plain Java class with no web dependency, which is why it saw early adoption for generating emails and reports as well as web pages.
More Related questions...