API / Apache Velocity Interview questions
Explain the internal working of the Velocity template parsing process?
Velocity's parser isn't hand-written; it's generated from a grammar file using JavaCC (Java Compiler Compiler), a parser generator, which produces the actual Java parsing classes used at build time.
Each node type in the resulting AST, an ASTIfStatement, an ASTReference, an ASTForeachStatement, and so on, knows how to render itself given a rendering context; walking that tree during merge() is essentially the interpreter step, separate from the parsing step shown above.
Because parsing only happens once per template (assuming caching is on), the JavaCC-generated grammar's performance matters far less for steady-state throughput than the tree-walking render step does, which is why caching configuration has a much bigger practical impact than parser micro-optimizations.
More Related questions...