Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:57+00:00 2026-05-25T02:44:57+00:00

I encounter this issue when calculating the price for a product but the formula

  • 0

I encounter this issue when calculating the price for a product but the formula changes nearly every day because of marketing schemes, discounts, taxes…

So I think it would be great if I could write code such as the code below, so that I could change the script at runtime.

public BigDecimal calculate(String script) {
   return (BigDecimal) ScriptEngine.execute(script);
}

Is there any way to implement this using Java?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:44:58+00:00Added an answer on May 25, 2026 at 2:44 am

    Yes: Use the Scripting API.

    There are implementations to run scripts written in JavaScript, Groovy, Python and lots of other languages.

    [EDIT]

    Since it was mentioned in the comments: Be wary of security issues.

    There are several options:

    1. You allow end-customers to supply scripts (say in a web form)
    2. You don’t allow customers to supply scripts; if a script needs to be changes an administrator or developer must start a specific tool.
    3. You develop a system which only allows to execute “safe” scripts

    Option #3 doesn’t work (= only works for the most simple cases). There is a mathematical proof that a computer program can never tell what another program can potentially do without actually executing it.

    So you can get away with option #3 if you don’t allow to call methods (or only a very, very limited set of methods). But most scripting languages allow to access Java classes which means you can eventually get System.exit() or Runtime.exec(). This in turn means you have to write a parser which makes sure that the code doesn’t contain something odd.

    Which you will have to update every day because the customers will come up with new … err … interesting ways to use the feature.

    Also chances are that you’ll make a mistake – either the parser won’t accept valid input or it will let malicious code pass. Given the complexity of the problem, the chance is between 99.9999% and 100%.

    Option #1 means no security at all but after the third change, customers will berate you to adopt it. It will work for some time until the first script kiddie comes along and ruins everything. Guess whose fault that will be? The manager who hired his nephew… the kid?

    So a human will have to eyeball the scripts, fix all the bugs in them and configure the system to run them. Option #2 will cause all kinds of griefs, too, but it will cause less grief, all things considered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encounter this issue pretty consistently when trying to merge a branch back into
This is something I encounter frequently, but I don't know the elegant way of
I currently encounter an issue with Chrome and Safari but not with Firefox. I'm
I work with evil-mode under Emacs so I encounter this issue that Emacs display
We encounter an issue with Safari 5.x in Windows 7 as explained in this
I've encountered this issue on two different machines and can't figure out what the
I am seeking to use ViewPager 's getCurrentItem() method I've encountered this issue before
I encountered an issue while I was revising my session library today, and this
Following this discussion , I've encountered a bad access issue; A loop has several
Looking back at my past projects I often encounter this one: A client or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.