Java解释器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3504396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java interpreter?
提问by Skizit
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?
有在线翻译吗?我可以在哪里扔一两行 java 到它,它会输出结果?
回答by Vladimir
Use bsh. It's a java-based shell.
使用 bsh。这是一个基于java的shell。
回答by Marimuthu Madasamy
ideone.comwhich supports Java and many other languages.
ideone.com支持 Java 和许多其他语言。
回答by John Kugelman
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 exampleI just typed in.
查看Ideone.com。您可以输入一个 Java 程序,它会编译它,然后为您运行它并显示输出。这是我刚刚输入的hello world 示例。
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
结果:成功时间:0.1s 内存:213376 kB 返回值:1
输入:无
输出:无
标准错误:
线程“main”中的异常 java.lang.NoSuchMethodError: main
Oops, I forgot to declare main as static!
糟糕,我忘了将 main 声明为 static!
回答by Noel M
Don't forget Jython
不要忘记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:
确实,它不是问题意义上的解释器,因此是公平的否决票。但是 IMO,可以向它抛出“一些”Java 代码,它会输出结果:
>>> 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 :)
我只是相信聪明的开发人员能够非常有效地利用这一点。我知道它过去对我有帮助:)
回答by Enno Shioji
Eclipse's built-in feature "scrap book"could be pretty close to what you want.
Eclipse 的内置功能“剪贴簿”可能非常接近您的需求。
回答by Johannes Wachter
If you have Groovyinstalled, the Groovy Consolealso works with Java Code.
如果你已经Groovy的安装中,Groovy的控制台还与Java代码。
回答by Wilfred Hughes
Your best bet is probably http://www.javarepl.com/but there are several other options:
您最好的选择可能是http://www.javarepl.com/,但还有其他几种选择:
If you require the interpreter to support Java syntax exactly, then ideone.comwill let you evaluate arbitrary Java code.
如果您要求解释器完全支持 Java 语法,那么ideone.com将让您评估任意 Java 代码。
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.
如果要评估 Java 片段,可以使用 Groovy 解释器。Java 代码通常也是有效的 Groovy,而且 Groovy 不会强制您定义整个类。有一个在线 Groovy 解释器。
If you don't require the interpreter to be online, there's also the Eclipse scrap book, DrJava, and BeanShell2which all allow Java to be interpreted.
如果您不需要在线解释器,还有Eclipse 剪贴簿、DrJava和BeanShell2,它们都允许解释 Java。
回答by dm78
回答by user1409472
Use xbsh, install it in ubuntu with:
使用 xbsh,在 ubuntu 中安装它:
$ sudo aptitude install bsh
$ sudo aptitude install bsh
that is a graphical and enhanced interface to bsh i.e. BeanShell
这是 bsh 的图形和增强界面,即 BeanShell
run it with:
运行它:
$ xbsh
$ xbsh
回答by Neil Chowdhury o_O
https://repl.it/languages/java
https://repl.it/languages/java
It's a nice interpreter and works fine, but might lag a little sometimes
这是一个很好的解释器并且工作正常,但有时可能会滞后一点