
- 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 can we avoid compilation errors in JShell in Java 9?
JShell is an interactive tool that enables us to execute java code and displays the output instantly. JShell is the REPL(Read-Evaluate-Print-Loop) tool that runs from the command-line prompt. If we need to avoid the compilation-errors in JShell, then we must declare those variables before using it. The error message in JShell can use the notation "^--^" to highlight an error.
In the below code snippet, the declaration of an int variable "div" attempts to use variables: num1, and num2 that has not been declared, so JShell reports a compilation error, indicating that the compiler was unable to find those variables.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> int div = num1 / num2 | Error: | cannot find symbol | symbol: variable num1 | int div = num1 / num2; | ^--^ | Error: | cannot find symbol | symbol: variable num2 | int div = num1 / num2; | ^--^
In the below code snippet, JShell displays the variable’s name: num1 and num2 followed by double equal and greater-than signs (==>).
jshell> int num1 = 35 num1 ==> 35 jshell> int num2 = 7 num2 ==> 7 jshell> int div = num1 / num2 div ==> 5
- Related Articles
- How can we implement a map in JShell in Java 9?
- How can we customize the start of JShell in Java 9?
- How can we execute snippets by ID in JShell in Java 9?
- How can we load a source code into JShell in Java 9?
- How can we import a gson library in JShell in Java 9?\n
- How to Avoid Errors in Java Code?
- How can we avoid a deadlock in Java?
- JShell in Java 9?
- How to debug JShell in Java 9?
- How to get JShell documentation in Java 9?
- What are the rules we need to follow in 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 implement java.time.LocalDate using JShell in Java 9?
