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 4064292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:50:11+00:00 2026-05-20T15:50:11+00:00

I am aware that by default Java does not have the so-called eval (what

  • 0

I am aware that by default Java does not have the so-called eval (what I pronounce as “evil”) method. This sounds like a bad thing—knowing you do not have something which so many others do. But even worse seems being notified that you can’t have it.

My question is: What is solid reasoning behind it? I mean, Google’ing this just returns a massive amount of old data and bogus reasons—even if there is an answer that I’m looking for, I can’t filter it from people who are just throwing generic tag-words around.

I’m not interested in answers that are telling me how to get around that; I can do that myself:

Using Bean Scripting Framework (BSF)

File sample.py (in py folder) contents:

def factorial(n): 
    return reduce(lambda x, y:x * y, range(1, n + 1))

And Java code:

ScriptEngine engine = new ScriptEngineManager().getEngineByName("jython");
engine.eval(new FileReader("py" + java.io.File.separator + "sample.py"));
System.out.println(engine.eval("factorial(932)"));

Using designed bridges like JLink

example

This is equivalent to:

String expr = "N[Integrate[E^(2 y^5)/(2 x^3), {x, 4, 7}, {y, 2, 3}]]";
System.out.println(MM.Eval(expr));
//Output: 1.5187560850359461*^206 + 4.2210685420287355*^190*I

Other methods

  • Using Dijkstras shunting-yard algorithm or alike and writing an expression evaluator from scratch.
  • Using complex regex and string manipulations with delegates and HashMultimaps.
  • Using Java Expressions Library
  • Using Java Expression Language
  • Using JRE compliant scripting language like BeanShell.
  • Using the Java Assembler and approach below or direct bytecode manipulation like Javaassist.
  • Using the Java Compiler API and reflections.
  • Using Runtime.getRuntime().exec as root
  • 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-20T15:50:12+00:00Added an answer on May 20, 2026 at 3:50 pm

    “eval” is only available in scripting languages, because it uses the same interpreter that runs the rest of the code; in such languages the feature is free and well integrated, as in scripting environment it makes little difference if you run a string or a “real” function.

    In copiled languages, adding “eval” would mean bundling the whole compiler – which would defy the purpose of compiling. No compiled language I know (even dynamic ones, like ActionScrip3) has eval.

    Incidentally, the easiest way to eval in Java is the one you forgot to mention: JRE 1.6 comes with Javascript engine, so you can eval any Javascript in two lines of code. You could even argue that the presuposition of your question is false. Java 1.6 bundles a very advanced expression evaluator.

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

Sidebar

Related Questions

I'm aware that Python 3 fixes a lot of UTF issues, I am not
I am aware that in .NET there are three timer types (see Comparing the
I am currently aware that ASP.NET 2.0 is out and about and that there
I'm fully aware that set division can be accomplished through a series of other
I am aware that you can lock an object in c# using lock but
I'm aware that in Vim I can often repeat a command by simply adding
I recently became aware that the strdup() function I've enjoyed using so much on
I'm aware that in WPF you want to keep the sizes of controls as
OK, I'm aware that triple-quotes strings can serve as multiline comments. For example, Hello,
Disclaimer Yes, I am fully aware that what I am asking about is totally

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.