简体   繁体   中英

Is there any Python-like interactive console for Java?

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

Yes; jshell , and before that some close approximations are Groovy , Clojure , Scala , and the Bean Shell .

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

试试Java博士的 “交互窗格”。

JShell现在是Java 9的标准.JShell简介

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.

您也可以执行Scala交互式解释器。

You can use BeanShell to run arbitrary Java code. If you want Eclipse integration, EclipseShell has BeanShell support.

您可能对Groovy感兴趣。

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM