This article demonstrates how one can externalize business logic in JavaScript and use the Nashorn engine to execute that business logic at runtime.
Here is the link to the article introducing Scripting in Java:
Introduction to Scripting In Java
Enjoy 🙂 !!!