Is there something like python's interactive REPL mode, but for Java?
edit Since Java 9 there's JShell
Original answer follows
You can also use Groovy Console. It is an interactive console where you can do what you want. Since Groovy also includes classes from the core java platform, you'll be able to use those classes as well.
It looks like this:
Eclipse has a feature to do this, although it's not a loop. It's called a "Scrapbook Page". I assume the analogy is supposed to be that you have a scrapbook where you collect little snippets of code.
Anyway, to make it work, open a project in Eclipse (your Scrapbook Page is going to be associated with a project -- Eclipse likes it when projects own things).
Then:
- In the project navigator window, select a folder that exists somewhere in your project.
- Either select the menu File -> New -> Other, or hit Control-N.
- Select Java -> Java Run/Debug -> Scrapbook Page.
- Hit "Next", then give it a filename, then hit "Finish".
Now you have a scrapbook page. Type some code, like maybe this:
System.out.println(System.getProperties());
Then select the text with the mouse, and either hit Control-U or select "Execute" from the context menu. The code will run and the output will appear on the console.
You can also type an expression, select it, and select Display from the context menu. It'll evaluate the expression and print its type. For example, running Display on 1 + 2
will print (int) 3
.