I know that you are able to do this in the command line with python. By simply entering "python3" in the terminal you can write and run python code on the spot. Is there a way to do this with java in the command line as well without having to first create a file and then changing directory to it, and then using vim/nano to edit the file, and then typing javac and java to run the file?
Asked
Active
Viewed 168 times
1
-
Try https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm – Stephen C Dec 25 '20 at 05:20
-
1[JEP 330](https://openjdk.java.net/jeps/330) (Java Enhancement Proposal) – Abra Dec 25 '20 at 08:00
1 Answers
4
Yes. As of Java 9 there is a Java REPL called jshell.
$ jshell
| Welcome to JShell -- Version 13.0.2
| For an introduction type: /help intro
jshell> System.out.println(System.getProperty("os.name"));
Mac OS X

Elliott Frisch
- 198,278
- 20
- 158
- 249
-
1[Is it my duty to check for duplicate questions before answering?](https://meta.stackoverflow.com/questions/326622/is-it-my-duty-to-check-for-duplicate-questions-before-answering) – Abra Dec 25 '20 at 08:01