Is there a way to run short bits of Java code without compiling?

后端 未结 9 1270
無奈伤痛
無奈伤痛 2020-12-25 15:33

Is there a way to run or simulate running Java statements (kind of like IDLE - the Python GUI) without compiling and running the executable? I want to quickly test statement

相关标签:
9条回答
  • 2020-12-25 16:14

    As of Java 11 (JEP 330) it is now possible to run Java files directly with the java tool:

    java Factorial.java 3 4 5
    
    is informally equivalent to
    
    javac -d <memory> Factorial.java
    java -cp <memory> Factorial 3 4 5
    

    Java also added support for "shebang" files.

    For more details see: http://openjdk.java.net/jeps/330

    0 讨论(0)
  • 2020-12-25 16:14

    You should be able to use Beanshell to do this:

    http://www.beanshell.org/download.html

    Your other alternative, if you're using Eclipse, is to make use of the scrapbook functionality:

    http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.user/tasks/task-create_scrapbook_page.htm

    0 讨论(0)
  • 2020-12-25 16:17

    you might want to checkout janino http://docs.codehaus.org/display/JANINO/Home also ..

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