Download Free/Trial Version Of Janino
Janino is a compiler that reads a Java expression, block, or source file, and generates Java bytecode that is loaded andexecuted directly. It is not intended to be a development tool, but an embedded compiler for run-time compilation purposes, such asexpression evaluators or "server pages" engines like JSP.PropertiesThe major design goal was to keep the compiler small and simple, while partially sacrificing completeness. I don't like the idea of carryingaround huge libraries for simple applications. See Parser for the list of implemented and missing language features.When do you need an efficient expression evaluator?Say you build an e-commerce system, which computes the shipping cost for the items that the user put into his/her shopping cart. Becauseyou don't know the merchant's shipping cost model at implementation time, you could implement a set of shipping cost models that come tomind (flat charge, by weight, by number of items, ...) and select one of those at run-time.In practice, you will most certainly find that the shipping cost models you implemented will rarely match what the merchant wants, so you mustadd custom models, which are merchant-specific. If the merchant's model changes later, you must change your code, re-compile andre-distribute your software.Because this is so unflexible, the shipping cost expression should be specified at run-time, not at compile-time. This implies that the expressionmust be scanned, parsed and evaluated at run-time, which is why you need an expression evaluator.A simple expression evaluator would parse an expression and create a "syntax tree". The expression "a + b * c", forexample, would compile into a "Sum" object who's first operand is parameter "a" and who's second operand is a"Product" object who's operands are parameters "b" and "c". Such a syntax tree can evaluated relativelyquickly. However, the run-time performance is about a factor of 100 worse than that of native Java code.
Tags: java, compiler, embedded, expression, evaluation, script, scripting, jvm, virtual, machine, bytecode, runtime, compilation, jsp, server, pages,
