- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How JShell tool works internally in Java 9?
JShell tool has introduced in Java 9 that provides a fast and friendly environment that enables us to quickly explore, discover, and experiment with Java language features and extensive libraries.
When the code entered into the JShell console, it is processed by JLine. It is a Java library that allows us to capture on a console. Once the code has been entered, it is parsed by JShell parser in order to determine its type (method, variable, etc.).
JShell Parser is wrapped in a class with the following rules:
- All imports are placed at the top of this class.
- Variables, methods and class declarations become static members of this class.
- Expressions and declarations are wrapped in a method inside this class.
After this step, the generated source code is analyzed and compiled in Bytecode by the Java compiler, then sent to a process running JVM in order to load and execute the code.
In the below code snippet, we can able to launch the JShell tool by simply typing "jshell" in command-line prompt.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell>
When JShell starts, we have a command prompt waiting for input. There are two types of commands that can be entered: JShell internal commands begin with a “/” and Java code.
In the below code snippet, we can able to print both internal commands like "/list" and Java code like System.out.println().
jshell> System.out.println("Tutorialspoint") Tutorialspoint jshell> /list 1 : System.out.println("Tutorialspoint")
- Related Articles
- How to implement JShell using JavaFX in Java 9?\n
- How to get system properties in JShell in Java 9?\n
- How to re-execute existing snippets in JShell in Java 9?\n
- JShell in Java 9?
- How to debug JShell in Java 9?
- How can we import a gson library in JShell in Java 9?\n
- How to get JShell documentation in Java 9?
- How to create JShell instance programmatically in Java 9?
- How to reset the JShell session in Java 9?
- How to implement java.time.LocalDate using JShell in Java 9?
- How to create a thread in JShell in Java 9?
- How to import external libraries in JShell in Java 9?
- How to handle an exception in JShell in Java 9?
- How to create scratch variables in JShell in Java 9?
- How to implement a String in JShell in Java 9?