are there any interpretors available online? Where I could just throw a line or two of java into it and it would output the result?
-
5Hav you looked into BeanShell (http://www.beanshell.org/)? It's not online but might do what you want. – FrustratedWithFormsDesigner Aug 17 '10 at 15:55
-
Bear in mind that Java is a staticaly typed compiled language so it's not possible to interactively interpret strict Java syntax. BeanShell is great, but it's not strict Java. But then, any online interpreter sandbox even for an interpreted language like Python is going to have massive limitations. http://try-python.mired.org/ – Simon Hibbs Aug 17 '10 at 16:02
-
2@SimonHibbs It actually is possible to write an interpreter for a statically compiled language, such as C or Java. There are some interpreters for C described here: stackoverflow.com/questions/584714/… – Anderson Green Mar 1 at 4:28 – Anderson Green Mar 15 '13 at 00:24
-
1Try [jshell](https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm) -- available since Java 9 – ovo May 14 '19 at 17:12
10 Answers
Don't forget Jython
Edited answer:
True, it is not an interpreter as in the sense of the question, so a fair downvote. But IMO, it's possible to throw "some" Java code towards it, and it'll output the result:
>>> from java.lang import System
>>> System.out.println("Hello world")
Hello world
>>> from java.util import Random
>>> r = Random()
>>> r.nextInt()
572839857
>>> r.nextInt(2)
0
I just believe that a smart developer would be able to make quite efficient use of this. I know it's helped me in the past :)

- 15,812
- 8
- 39
- 47
-
4Jython is not a Java interpreter. It's an implementation of Python for the JVM. – Thomas Owens Aug 17 '10 at 16:29
-
6The downvote was very unjustified, for the reason explained. Jython **is** very useful when exploring a Java API. – olefevre Apr 04 '11 at 14:59
Your best bet is probably http://www.javarepl.com/ but there are several other options:
If you require the interpreter to support Java syntax exactly, then ideone.com will let you evaluate arbitrary Java code.
If you want to evaluate Java snippets, you could use a Groovy interpreter. Java code is generally valid Groovy too, and Groovy doesn't force you to define a whole class. There's an online Groovy interpreter.
If you don't require the interpreter to be online, there's also the Eclipse scrap book, DrJava, and BeanShell2 which all allow Java to be interpreted.

- 29,846
- 15
- 139
- 192
Use bsh. It's a java-based shell.

- 9,913
- 4
- 26
- 37
-
It looked promising. I installed it on Fedora with `yum install bsh` but how do I run it? `bsh` on the command line yields `bsh: command not found` – John Smith Optional Jul 21 '14 at 09:39
-
Ok, I finally managed to run the interpreter with the following command (on Fedora): `java -cp /usr/share/java/bsh.jar bsh.Interpreter` – John Smith Optional Jul 21 '14 at 09:46
If you have Groovy installed, the Groovy Console also works with Java Code.

- 2,715
- 17
- 17
-
1just a warning: I like the Groovy Console but Groovy is not Java. There are some syntactical parts, which behave differently or don't work in Groovy – Hachi Feb 24 '13 at 19:49
-
jGRASP contains a very useful interpreter that I've used to check small portions of code and do minor string processing.
This may still be the recommended IDE for beginning CS students at Auburn University.

- 1,570
- 1
- 16
- 28
-
When I was still in uni, I always coded Java in Netbeans with jGRASP open in the background for exactly this usage. – Dave Oct 03 '13 at 18:57
Check out Ideone.com. You can type in a Java program and it'll compile it and then run it for you and display the output. Here's a hello world example I just typed in.
Code:
public class Main {
public void main(String[] arguments) {
System.out.println("Hello world!");
}
}
Output:
result: success time: 0.1s memory: 213376 kB returned value: 1
input: no
output: no
stderr:
Exception in thread "main" java.lang.NoSuchMethodError: main
Oops, I forgot to declare main as static!

- 1
- 1

- 349,597
- 67
- 533
- 578
-
2It seems that even the "Hello World" programs don't run correctly the first time:) – Petar Minchev Aug 17 '10 at 16:04
Eclipse's built-in feature "scrap book" could be pretty close to what you want.

- 5,100
- 13
- 43
- 62

- 26,542
- 13
- 70
- 109
https://repl.it/languages/java
It's a nice interpreter and works fine, but might lag a little sometimes

- 398
- 4
- 8
Use xbsh, install it in ubuntu with:
$ sudo aptitude install bsh
that is a graphical and enhanced interface to bsh i.e. BeanShell
run it with:
$ xbsh

- 11
- 2