
- 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
Using Variables in JShell of Java 9
In JShell 9, variables can be declared during a session. Once the user has logged into the session, they can declare a variable as follows −
jshell> int val = 56 ;
Italics indicate the terminal, once the user has logged in to their session.
The above line would print the below output. The semicolon in the above line is optional, and it will run fine without the semicolon also.
Output
val = = > 56
When an integer value is defined by assigning it to a variable name on the JShell, and it is executed, by pressing ‘Enter’ key, it is displayed on the next line of JShell command line.
Incase we don’t assign a variable to a value and just print it on the JShell, it will assign a variable to the value −
jshell> 79
Output
$3 = = > 79
When an integer value is defined without assigning it to a variable name on the JShell, and it is executed, by pressing ‘Enter’ key, it is displayed on the next line of JShell command line. Here, JShell itself assigns a variable name to the most recently entered variable value.
- Related Articles
- How to create scratch variables in JShell in Java 9?
- How to define expressions, variables, and methods in JShell in Java 9?
- JShell in Java 9?
- How to implement java.time.LocalDate using JShell in Java 9?
- Package Imports in JShell of Java 9
- How to implement an ArrayList using JShell in Java 9?
- How to implement JShell using JavaFX in Java 9?\n
- How to debug JShell in Java 9?
- How to get JShell documentation in Java 9?
- How can we customize the start of JShell in Java 9?
- How to modify the default editor of JShell in Java 9?
- How to create JShell instance programmatically in Java 9?
- How to reset the JShell session in Java 9?
- How JShell tool works internally in Java 9?\n
- How to print the pattern of stars in JShell in Java 9?
