Operators in Java

by Jasleen Chhabra | Updated on 24 August 2024

Operators in Java

Basic operators in Java are fundamental building blocks for performing operations on variables and values. Here's an overview of the basic operators in Java:

  1. Arithmetic Operators:
    • Addition (+): Adds two operands.
    • Subtraction (-): Subtracts the second operand from the first.
    • Multiplication (*): Multiplies two operands.
    • Division (/): Divides the first operand by the second.
    • Modulus (%): Returns the remainder of the division operation.
  2. Assignment Operators:
    • Assignment (=): Assigns the value on the right to the variable on the left.
    • Compound Assignment (+=, -=, *=, /=, %=): Combines arithmetic operation with assignment.
  3. Increment/Decrement Operators:
    • Increment (++): Increases the value of a variable by 1.
    • Decrement (--): Decreases the value of a variable by 1.
  4. Comparison Operators:
    • Equal to (==): Compares two values for equality.
    • Not equal to (!=): Compares two values for inequality.
    • Greater than (>): Checks if the first operand is greater than the second.
    • Less than (<): Checks if the first operand is less than the second.
    • Greater than or equal to (>=): Checks if the first operand is greater than or equal to the second.
    • Less than or equal to (<=): Checks if the first operand is less than or equal to the second.
  5. Logical Operators:
    • Logical AND (&&): Returns true if both operands are true.
    • Logical OR (||): Returns true if at least one of the operands is true.
    • Logical NOT (!): Returns the opposite boolean value of the operand.
  6. Bitwise Operators:
    • Bitwise AND (&): Performs a bitwise AND operation.
    • Bitwise OR (|): Performs a bitwise OR operation.
    • Bitwise XOR (^): Performs a bitwise XOR (exclusive OR) operation.
    • Bitwise Complement (~): Flips the bits of its operand.
    • Left Shift (<<): Shifts the bits of the first operand to the left by the number of positions specified by the second operand.
    • Right Shift (>>): Shifts the bits of the first operand to the right by the number of positions specified by the second operand.
    • Unsigned Right Shift (>>>): Shifts the bits of the first operand to the right by the number of positions specified by the second operand, filling in the leftmost bits with zeros.

These operators are used extensively in Java for various operations like mathematical calculations, logical evaluations, bitwise manipulations, and more.

 



FAQ

Any Questions?
Look Here.

Related Articles

Abstraction in Java

Binding in Java

Break Statement in Java

Classes & Objects in Java

Collections Framework in Java

Comments in Java

Continue Statement in Java

Control Statements in Java

Data Types in Java

Do While-Loop in Java

Encapsulation in Java

Exception Handling in Java

For-Loop In Java

Hello World Program in Java

If-else Statement in Java

Inheritance in Java

Introduction to Java

Java Database Connectivity (JDBC)

Java Development Tools and Frameworks

Java GUI (Graphical User Interface) Programming

Java I/O

Java Vs. C++

Methods and Constructors in Java

Multithreading in Java

Object Oriented Programming in Java

Polymorphism in Java

Scanner Class in Java

Setting Up Java Environment

Static Keyword in Java

Super Keyword in Java

Switch Statement in Java

This Keyword in Java

Variables in Java

While-Loop in Java