How do you start a JShell session from the command line?

Java MCQ: How do you start a JShell session from the command line?

a) Run the command java -jshell
b) Run the command jshell
c) Run the command java -jar jshell.jar
d) Run the command shelljava

Answer:

b) Run the command jshell

Explanation:

To start a JShell session from the command line, you run the command jshell. JShell is a REPL (Read-Eval-Print Loop) tool introduced in Java 9 that allows developers to interactively write and execute Java code snippets. By typing jshell in the command line, you enter an interactive environment where you can experiment with Java code, test new APIs, and debug logic on the fly.

JShell is particularly useful for quick prototyping, learning, and exploring Java language features without needing to write a full Java program or set up an IDE. Once in JShell, you can type Java expressions, statements, and methods, and see the results immediately.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top