How do I log in to a console or GUI as if it were real Java code?

I want to be able to enter java commands / code to execute at runtime (while the "constant" program is running) in the same way or as close as possible to the same code will be executed if it was present in the program source code (programmed as part software) using a GUI element like jTextArea.


The following StackOverflow questions seem to be related, but like the answers to them, it seems not what I'm looking for.

How to get input from console class in Java?

Using GUI for console input and output in java

I don’t want to “be able to run actions from specific console inputs and print feedback in the console”, as it seems, in the case of the console applications described in this question, and the answers.

What I want is "to be able to run valid Java code, which I cannot predict and control, from input from the console (or GUI)."

NOTE: “I cannot predict and control” here refers to the “developer” ... But, of course, I can predict and “control” it if I am the one who enters the code because the “user” is done.


java , , ", "... , .

, , for(int i=0; i<3; i++){System.out.println(i);} "GUI" (jTextArea), , "" () "?" ) , , :

0
1
2

, :

  • ?
  • , ? (, , ?)
+3
4

JavaCompiler. String.

E.G. . STBC , .

STBC GUI

:

STBC 1.6+ Java Plug-In * JDK (AKA SDK).

(*) API, STBC, tools.jar, JDK (, , " JRE" JDK tools.jar). - , -.

+2

JavaCompiler, :

fooobar.com/questions/131386/...

, , , evaluate a String of code:

.

+2

BeanShell

" , BeanShell Java, , ".

+1

, , Googlers:

I would recommend JavaREPL , the source of which is available here: https://github.com/albertlatacz/java-repl

What AlmightyR requests is called Read-Eval-Print-Loop (REPL) for the Java language, which is what JavaREPL provides.

JavaREPL has an online demo version: http://www.javarepl.com/console.html

JavaREPL also has an Intellij plugin and CLI version that are associated with the Github repository.

Currently, it looks like an abandoned one, but maybe it just doesn't need to be supported?

0
source

All Articles