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

  • Home
  • SEARCH
  • 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 6372155
In Process

The Archive Base Latest Questions

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

Basically I want to be able to do be able to parse a JavaScript-like

  • 0

Basically I want to be able to do be able to parse a JavaScript-like syntax. For example:

var results = system.function('example');  

if(results == "hello") {  
   console_print("ding dong.");  
}  

So basically you get it, results will be a “string” and system.function will call a Java method, and those results will go into the results string.

I want to be able to do basic math, and validation in this as well, but I want this done in Java. Any ideas?

  • 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-25T01:11:58+00:00Added an answer on May 25, 2026 at 1:11 am

    If you’re willing to use JavaScript (not just JavaScript-like), and you’re using Java 1.6+, then you can use the Scripting API:

    import javax.script.*;
    
    public class Main {
    
      public static void main (String[] args) throws Exception {
    
        String source =
            "var system = new Array();                       \n" +
            "system['foo'] = function(s) { return 'hello'; } \n" +
            "                                                \n" +
            "var results = system.foo('example');            \n" +
            "                                                \n" +
            "if(results == \"hello\") {                      \n" +
            "  print(\"ding dong.\");                        \n" +
            "}                                               \n";
    
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
        engine.eval(source);
      }
    }
    

    which will print:

    ding dong.
    

    to the console.

    And to invoke Java methods from the scripting language, you could give BeanShell a try:

    package test;
    
    import bsh.Interpreter;
    
    public class Main {
    
      public static void foo(Object param) {
        System.out.println("From Java, param=" + param);
      }
    
      public static void main (String[] args) throws Exception {
    
        Interpreter i = new Interpreter();
        i.eval("a = 3 * 5; test.Main.foo(a);");
      }
    }
    

    which will print:

    From Java, param=15
    

    The core interpreter JAR of BeanShell is only 143 KB: more lightweight than that will be difficult, IMO.

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

Sidebar

Related Questions

Okay, so basically I want to be able to retrieve keyboard text. Like entering
Can ASMX have an IOC like WCF? Basically I want to be able to
Basically we want to be able to somehow synchronize our .NET application's contacts with
Basically, what I want to is be able to explore an ActiveX DLL. I
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
Given this structure.. I basically want to be able to take a list of
Basically i want to be able to get a 32bit int and attach its
Basically I want to be able to call jQuery from FireBug, place code that
I basically want to use link_to to link to the index method of a
So I basically want to have a static method in my AR class to

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.