Aritz Lopez
Aritz Lopez

Reputation: 169

Run simple programs w/o making a new class in IntelliJ IDEA

I often need to run simple (one/two-line) programs to quickly get the output of a method I'm developing. However, to do so I need to create a new class, add a main method, and write the code there.

I was wondering if there is a simpler way to do this, because I do this quite often.

An example would be:

FormatHelper.format("\\1Does \\2This work?");

I know there needs to be some kind of context for a program to run (classpath, etc.), but I was thinking IntelliJ could handle it for me.

Upvotes: 2

Views: 148

Answers (5)

Aritz Lopez
Aritz Lopez

Reputation: 169

There is an IntelliJ IDEA plugin called Java REPL, which implements exactly what I was looking for.

The only downside (if you can call it a downside) is that you have to install a plugin

Upvotes: 0

Marcin Szymczak
Marcin Szymczak

Reputation: 11453

You should use http://ideone.com/ which is an online IDE.

Just write your one line code and hit run button

Upvotes: 0

maba
maba

Reputation: 48105

You can start the Groovy Shell from the Tools menu and run the expression there. Java expressions will work just fine.

Upvotes: 1

Flight Odyssey
Flight Odyssey

Reputation: 2287

This may not be exactly what you described, but check out this question: 'Immediate' window for IntelliJ

It appears to be related, and indicates that in IntelliJ 9 "There is ALT-F8 to evaluate an expression"

Upvotes: 1

victorantunes
victorantunes

Reputation: 1169

I just often hold a Test Class on a test package and do everything algorithm testing-related inside my main method there.

But to directly answer your question, AFAIK no IDE will do what you want.

On a side note, it may be worth trying ideone or compileonline

Upvotes: 0

Related Questions