1

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?

Louis Nguyen
  • 31
  • 1
  • 5

1 Answers1

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