Java Programming Tutorial Index

Java Fundamentals

The Java Logical Operators work on the Boolean operand. It's also called Boolean logical operators. It operates on two Boolean values, which return Boolean values as a result.

Operator Meaning Work
&& Logical AND If both operands are true then only "logical AND operator" evaluate true.
|| Logical OR The logical OR operator is only evaluated as true when one of its operands evaluates true. If either or both expressions evaluate to true, then the result is true.
! Logical Not Logical NOT is a Unary Operator, it operates on single operands. It reverses the value of operands, if the value is true, then it gives false, and if it is false, then it gives true.

Program to Show Logical Operators Works


public class logicalop {
 public static void main(String[] args) {
  //Variables Definition and Initialization
  boolean bool1 = true, bool2 = false;

  //Logical AND
  System.out.println("bool1 && bool2 = " + (bool1 && bool2));
  //Logical OR
  System.out.println("bool1 || bool2 = " + (bool1 | bool2) );
  //Logical Not
  System.out.println("!(bool1 && bool2) = " + !(bool1 && bool2));



bool1 && bool2 = false
bool1 || bool2 = true
!(bool1 && bool2) = true

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram