How do you use JShell with a simple code example?

JShell is a tool introduced in Java 9 that allows you to interactively evaluate Java expressions, statements, and programs. It is particularly useful for testing snippets of code and learning Java without the need to create formal classes and methods.

// Start JShell by running the command 'jshell' in your terminal jshell // You can declare a variable int number = 10; // Print the variable System.out.println(number); // Perform a simple calculation int sum = number + 5; System.out.println("Sum: " + sum);

JShell Java interactive programming Java REPL