tags:

views:

967

answers:

8

I spent a lot of time programming in Java recently, and one thing I miss from scripting languages was the ability to test them in a console.

To quickly test a java program, I have to edit a file, then turn it to bytecode and execute it. Even using an IDE, it loses its fun after the 372 th time.

I would like to know if there is a product out there that features anything like an interactive console (I bet you need a JIT compiler) and some autocompletion (with relexivity, I suppose it's possible).

Maybe that's something very common that I just don't know about or something completely impossible, but its worst asking :-)

+5  A: 

Not entirely, because Java isn't well defined without the structure of a class and so on. But some close approximations are in Groovy, Clojure, and the Bean Shell.

Charlie Martin
I like BeanShell.
Michael Myers
Agreed. I use BeanShell through [JDE](http://jdee.sourceforge.net/) in emacs; it's far from perfect, but it provides an interactive console, and decent completion support, both in the console and while editing your regular Java files.
Julian Squires
Indeed, it's very primitive but much better than nothing. Thank to you, and thanks to the guys who coded it :-)
e-satis
+1  A: 

You may be interested in Groovy.

Patrick
A: 

I've occasionally run into the same problem and have a partial solution. I keep around a file (as Charlie Martin said, Java needs its class contexts) that is little more than a test program. In a second window - a console - I have a script that I run that just checks the modification time of the source file every second or two. When it sees the source change, it re-compiles it (I'm usually fiddling in C, but I've done this with Java, as well) and executes the result.

It's not a great solution, but its a fast one-off and I've found it to be very useful.

+2  A: 

An approach that I have used to some degree of success is to debug in Eclipse and use the display view. What the display view gives you is the ability to manipulate the code currently running in the JVM through executing Java statements. Any object available at the particular break point you are stopped at is in scope within the display view. While this isn't exactly what you are looking for it does provide some of the features that a REPL provides for other programming environments. See Debugging with the Eclipse Platform for more information.

laz
+4  A: 

Funnily enough, you get an interactive console with Jython ! You don't get much more Python-like.

Brian Agnew
A: 

You can execute Scala interactive interpreter too.

stepancheg
A: 

Jgrasp IDE have a interactive console where you can test in, i use it a lot, and there is alos a debug view showing variabel etc efter you have deklare them.

It is opensoruce and you can get a copy att http://www.jgrasp.org/

// Anders

Anders
I looked around JGrasp, but couldn't find an interactive console
Casebash