JShell – REPL in Java
Read-Eval-Print Loop (REPL) is an environment where code can execute one line at a time. REPL became a standard part of Java in version 9. It is implemented in a tool called JShell. It serves two purposes:
- It provides an environment for learning Java without any background in programming.
- It provides a way to quickly test concepts, syntax, and libraries.
As such, you can execute Java code without the need for the usual decorations.
There are two ways we can use JShell. The first is to just enter the code that’s necessary to use the formula. Imagine that you want to verify the formula for compound interest, as shown in the source code. You can do that by just entering the necessary code to perform the calculation.
In the following code block, we have entered the four variable declarations with the values required for the calculation, followed by the line of code that performs the calculation and assigns it to a variable...