javaperformancescriptingjvm

Java as a scripting language for Java?


Is it possible to use Java as a scripting language for java? Or maybe somehow compile java scripts into java binarries at runtime? I did tried to search but couldn't find anything comprehensive except for some hacks...

I have experience with other languages and for example for C# I used lua which was quite convenient but now I need to acheive the utmost performance as calls for scripts will be about 1.000.000 per frame.

So I figured that adapting java itself as a scripting language for java program should provide me the best performance and compatibility.

Any suggestions?


Solution

  • BeanShell is a commonly used scripting solution for Java. It's a scripting language which is very Java-like.

    Other solutions exist which use the Java infrastructure and JVM, but with a different language. e.g. Scala, Groovy and Jython (a Java-compatible Python). The important thing to realise with all of these is that they'll interoperate with Java libraries created using standard Java, so you could trivially use (say) Scala to drive your Java-language created solution.

    The above all provide a REPL (read-eval-print-loop) so you can import, instantiate and interact with your objects in a dynamic command-line environment. That's very useful for testing and prototyping interactions, as well as testing your scripts.