Java 的交互式 shell,如 ipython

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/958806/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:34:03  来源:igfitidea点击:

Java's interactive shell like ipython

javashell

提问by Ross

I am quite new to Java and would like to learn Java using an interactive shell, like I did with Python using IPython.

我对 Java 很陌生,想使用交互式 shell 学习 Java,就像我使用 IPython 学习 Python 一样。

I have tried a few interactive shells, such as beanshell, jython, jythonconsole, and JyConsole. Most of them don't have tab completion like IPython does. Is there anything similar to IPython for java?

我尝试了一些交互式 shell,例如 beanshell、jython、jythonconsole 和 JyConsole。他们中的大多数没有像 IPython 那样的选项卡完成功能。有没有类似于 Java 的 IPython 的东西?

回答by Shane Miller

If you want an interactive option for use with java try using Dr Java or JGrasp, they both provide the same interactive option as does IDLE for python, plus being a fully based IDE with a debugger I prefer JGrasp to Dr Java. They also have a Dr Python so if you get used to Dr Java you can also use it with Python.

如果您想要与 java 一起使用的交互式选项,请尝试使用 Dr Java 或 JGrasp,它们都提供与用于 Python 的 IDLE 相同的交互式选项,而且作为带有调试器的完全基于 IDE,我更喜欢 JGrasp 而不是 Dr Java。他们还有一个 Dr Python,所以如果你习惯了 Dr Java,你也可以将它与 Python 一起使用。

Also Dr Java has a feature in which you can select from beginner, intermediate, advanced and full Java in order to limit what you can do with the language as you learn it. I never use that feature as I dont see the point in restricting parts of the langaue but I guess some teachers utilize it while teaching their students.

Dr Java 还具有一项功能,您可以在其中选择初级、中级、高级和完整 Java,以限制您在学习该语言时可以使用该语言进行的操作。我从不使用该功能,因为我不认为限制部分语言的意义,但我猜有些老师在教学生时会使用它。

回答by gavenkoa

groovysh:

常规

http://groovy.codehaus.org/Groovy+Shell

http://groovy.codehaus.org/Groovy+Shell

  • Rich cross-platform edit-line editing, history and completion thanks to JLine.
  • ANSI colors (prompt, exception traces, etc).
  • Simple, yet robust, command system with online help, user alias support and more.
  • User profile support
  • 由于 JLine,丰富的跨平台编辑行编辑、历史和完成。
  • ANSI 颜色(提示、异常跟踪等)。
  • 带有在线帮助、用户别名支持等的简单而强大的命令系统。
  • 用户资料支持

回答by SingleNegationElimination

You probably won't get much use out of using java interactively, as that language is strongly oriented toward compiling. The best route will probably just get a nice IDE, like eclipse, and get started with breakpoints and the debugger.

交互式地使用 java 可能不会有太大用处,因为该语言强烈地面向编译。最好的方法可能只是获得一个不错的 IDE,例如eclipse,然后开始使用断点和调试器。

回答by LB40

what beanshell have you used ? the old one ? Look at thisthey claim to provide completion

你用的是什么豆壳?旧的?看看这个他们声称提供完成

回答by Ross

I think I find a good enough alternative: JPype. JPype allows python programs having full access to java class libraries. With JPype and IPython, I can use all java functions while having very nice tab completion for the java classes.(After the class is imported though)

我想我找到了一个足够好的替代品:JPype。JPype 允许 python 程序完全访问 java 类库。使用 JPype 和 IPython,我可以使用所有 java 函数,同时为 java 类提供非常好的 tab 补全。(虽然在导入类之后)

回答by Tobske

Gayan Weerakutti already mentioned in a comment what I think should be the correct answer, too: JShell is part of the JDK since version 9. Try jshellon your terminal. Check out docs from Oracle about it.

Gayan Weerakutti 已经在评论中提到我认为应该是正确答案:JShell 从版本 9 开始就是 JDK 的一部分。jshell在你的终端上试试。查看Oracle 提供的有关它的文档

回答by lukmdo

Although I agree with TokenMacGuysaying:

虽然我同意TokenMacGuy 的说法:

The best route will probably just get a nice IDE, like eclipse
最好的方法可能只是得到一个不错的 IDE,比如 eclipse
因为我也来自交互式 shell 之类的工具必不可少的环境。所以我也可以建议你简单地使用类似的工具ipythonipython直接来自jythonjython/JPype.

That can be achieved or using JPypeas suggested by i-freakerof through jython:

可以实现或使用JPype所建议的i-freaker的通过的jython:

  1. Getting jython(check its running jython -c 'import os; print "Python meets %s" % os.name')
  2. Getting readrline(In case Mac sudo port install readline)
  3. Fallowing the steps from this blogor jython documentationto make java-readlinework
  4. So you have jythonwith readlineby now(Ctrl+Rin jython results in reverse-i-searchlike you know it from the shell). In order to get tab-completion like you know it form ipythonfallow the steps from this blog
  5. That should be it! In case you need patch for ipython 0.10 you can get it from here.
  1. 获取jython(检查它的运行jython -c 'import os; print "Python meets %s" % os.name'
  2. 获取readrline(如果 Mac sudo port install readline
  3. 使用此博客jython 文档中的步骤使 java-readline工作
  4. 所以你现在已经jython有了readlineCtrl+R在 jython 中的结果reverse-i-search就像你从 shell 中知道的那样)。为了像您所知道的那样获得制表符完成ipython,请执行此博客中的步骤
  5. 应该是这样!如果您需要 ipython 0.10 的补丁,您可以从这里获取

回答by Mapio

Give a look at https://github.com/Bachmann1234/java9_kernelyou can install a Java kernel for IPython and use it (also via the notebook).

看看https://github.com/Bachmann1234/java9_kernel你可以为 IPython 安装一个 Java 内核并使用它(也通过笔记本)。

回答by kai

IntelliJ IDEA has a groovy console with tab completion.

IntelliJ IDEA 有一个带有选项卡完成功能的 groovy 控制台。

open it: Tools -> Groovy Console...

打开它:工具 -> Groovy 控制台...