In scripting languages like Ruby/Python/Perl, we can start an interactive session and create new variables, and essentially execute whatever statements.
But in Java, I only know of a way to print arbitrary expressions - in Eclipse's debug-expression view.
There is no way to create new vars, and later utilize that var (though you can assign to pre-existing vars).
Is there any way to run Java in a interpreted IDE environment just like scripting languages?
3 Answers 3
Check out Groovy. If you want to stick to pure Java, I think Groovy will happily execute any valid Java code. You can poke at it via the GroovySH interactive shell.
Comments
Check out Beanshell It has been around a while. Also you can look at IDEOne website for an online IDE-like environment for several languages (not quite a shell). And yeah, I meant to mention Groovy too, which has the groovy shell.
Comments
As of Java 9 there will be a REPL available to allow you to start an interactive Java session.
It's called JShell, and you can read the original proposal: JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)
There are a number of blogs and articles exploring some of the features of JShell, if you'd like to see it in action.