Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 961
NewProger Avatar asked Dec 06 '12 16:12

NewProger


People also ask

Can we use Java as scripting language?

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).

What are scripting languages and why JavaScript is used?

A scripting language is a programming language that is interpreted. It is translated into machine code when the code is run, rather than beforehand. Scripting languages are often used for short scripts over full computer programs. JavaScript, Python, and Ruby are all examples of scripting languages.


2 Answers

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.

like image 178
Brian Agnew Avatar answered Oct 18 '22 13:10

Brian Agnew


You can use BeanShell for this, but Groovy, XTend, and Scala might make better choices.

like image 43
Peter Lawrey Avatar answered Oct 18 '22 13:10

Peter Lawrey