
- 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
What are the different "/vars" commands in JShell in Java 9?
JShell is an interactive command-line tool introduced in Java 9. It is also called a REPL tool that takes input, evaluates it, and prints output to the user.
In the JShell tool, it's possible to list all variables created by using the internal command "/vars". We have different "/vars" commands available in the JShell tool as listed below.
/vars /vars [ID] /vars [Variable_Name] /vars -start /vars -all
- /vars: This command allows to us display the list of all active variables of the current session.
- /vars [ID]: This command displays the variable and its value, corresponding to the entered ID. This ID corresponds to the name of the variable that JShell assigned to expression ($ 1, $ 2…).
- /vars [Variable_Name]: This command displays the variable [Variable_Name] and its value.
- /vars -start: This command allows us to display all variables that we have added to the JShell startup script.
- /vars - all: This command displays the list of all active, inactive, and loaded variables at startup.
In the below code snippet, created expression and variable. Then we can able to apply different "/vars" commands.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> 2 + 4 $1 ==> 6 jshell> /vars | int $1 = 6 jshell> int x = 20 x ==> 20 jshell> /vars | int $1 = 6 | int x = 20 jshell> /vars $1 | int $1 = 6 jshell> /vars x | int x = 20 jshell> /vars -all | int $1 = 6 | int x = 20 jshell> /drop x | dropped variable x jshell> /vars -all | int $1 = 6| int x = (not-active)
- Related Articles
- What are the different "/edit" commands in JShell in Java 9?
- What are the different "/types" commands in JShell in Java 9?
- What are the useful commands in JShell in Java 9?
- How to display different list commands in JShell in Java 9?
- What are the different shortcut keys in JShell in Java 9?
- What are the different feedback modes in JShell in Java 9?
- What are the different startup scripts in JShell in Java 9?
- What are the rules for external declarations in JShell in Java 9?
- JShell in Java 9?
- What are the different commands used in MySQL?
- What are the rules we need to follow in JShell in Java 9?
- What are the different module types in Java 9?
- What is a forward reference in JShell in Java 9?
- What is the use of the Tab key in JShell in Java 9?
- How to debug JShell in Java 9?

Advertisements