
- 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 to implement relational and logical operators in JShell in Java 9?
JShell has introduced in Java 9 that enables us to explore, discover, and experiment with Java language features, and extensive libraries.
The relational operators (==, != <, >, <=, >=) can be used mainly for comparison. It accepts operands of non-boolean primitive data types and returns a boolean value. JShell also supports logical operators that can be used in expressions. The logical operators can expect boolean operands. The expressions involving these operands can be used for forming boolean conditions in the code within if, for, and while statements. The logical operators include : "&& : logical AND", "|| : OR" and "! : NOT".
In the below two code snippets, we can implement relational operators using JShell.
Snippet-1
jshell> int i = 10; i ==> 10 jshell> i > 10; $2 ==> false jshell> i >= 10; $3 ==> true jshell> i < 10; $4 ==> false jshell> i <= 10; $5 ==> true jshell> i == 10; $6 ==> true jshell> i == 20; $7 ==> false
Snippet-2
jshell> int i = 15; i ==> 15 jshell> i >=15 $1 ==> true jshell> i <= 15 $2 ==> true jshell> i >= 15 && i <= 25 $3 ==> true jshell> i == 30; $4 ==> false jshell> i = 30; i ==> 30 jshell> i >= 15 && i <= 25; $5 ==> false
In the below code snippet, we can implement logical operators using JShell.
jshell> true && true $1 ==> true jshell> true && false $2 ==> false jshell> false && true $3 ==> false jshell> false && false $4 ==> false jshell> true || true $5 ==> true jshell> true || false $6 ==> true jshell> false || true $7 ==> true jshell> false || false $8 ==> false
- Related Articles
- Relational and Logical Operators in C
- How to implement java.time.LocalDate using JShell in Java 9?
- How to implement a String in JShell in Java 9?
- How to implement String utility and immutability in JShell in Java 9?
- How to implement HashMap, LinkedHashMap, and TreeMap in JShell in Java 9?
- How to implement an ArrayList using JShell in Java 9?
- How to implement JShell using JavaFX in Java 9?\n
- How to implement the encapsulation concept in JShell in Java 9?
- How to implement a lambda expression in JShell in Java 9?
- How to implement the Fibonacci series in JShell in Java 9?
- How to implement integer type conversion in JShell in Java 9?
- How to implement a Set interface in JShell in Java 9?
- How can we implement a map in JShell in Java 9?
- Java Relational Operators
- Java Logical Operators
