Is there something like python's interactive REPL mode, but for Java?

前端 未结 28 1022
一个人的身影
一个人的身影 2020-11-29 16:38

Is there something like python\'s interactive REPL mode, but for Java? So that I can, for example, type InetAddress.getAllByName( localHostName ) in a window, a

相关标签:
28条回答
  • 2020-11-29 16:52

    Beanshell 2

    0 讨论(0)
  • 2020-11-29 16:53

    There's an online REPL: http://www.javarepl.com/console.html

    Typing more to reach the character limit ...

    0 讨论(0)
  • 2020-11-29 16:54

    It's part of OpenJDK 9!

    A REPL called JShell (developed by Oracle) has been released as part of JDK 9.

    Just download JDK 9, and launch bin/jshell.

    Resources

    • blogs.oracle.com: Inside JShell
    • DZone: Java 9 (Part 2): JShell Step by Step
    • OpenJDK project Kulla
    • Java Enhancement Proposal, JEP 222: jshell: Java Shell (Read-Eval-Print Loop)
    0 讨论(0)
  • 2020-11-29 16:55

    While JRuby, BeanShell, Julian Fleischer's REPL are there Albert Latacz's REPL seems to be the latest and active.

    Tried it with a simple class definition, works fine.

    $ java -jar javarepl.jar
    Welcome to JavaREPL version 56 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_17)
    Type in expression to evaluate.
    Type :help for more options.
    
    java> public class Test {
        | public static void execute(String [] s) {
        |  System.out.println(54353 + s[0]);
        | }}
    
    java> Test.execute(new String [] {"234343"});
    54353234343
    
    java> System.exit(0);
    
    0 讨论(0)
  • 2020-11-29 16:56

    Seems nobody mentioned yet that Java (6, 7) ships a REPL console called jrunscript. It is language agnostic (so can be used with Jython, JRuby etc.). It defaults to JavaScript (Rhino) which is also bundled by default, and like the other languages you can access all the packages/objects available on the classpath.

    0 讨论(0)
  • 2020-11-29 16:56

    DrJava is an educational IDE that includes an REPL pane.

    There is an Eclipse plugin as well, but it hasn't worked for me. I think it just hasn't been updated in a while. So what I generally do is keep a DrJava window open for the "what happens if I do this" questions.

    EclipseShell might be good too, but I haven't used it yet.

    0 讨论(0)
提交回复
热议问题