// check whether the used functions or references are actually valid.
final Formula f = new Formula(formula);
// connects the parsed formula to the context. The context provides the
// operator and function implementations and resolves the references.
f.initialize(new DemoFormulaContext());
final Object o = f.evaluate();
JOptionPane.showMessageDialog(null, "The result is " + o,
"Result", JOptionPane.INFORMATION_MESSAGE);