Learn Best Java Operators List With Example in 2023

Java Operators List: Arithmetic, Relational, Logical, Bitwise and more

Java Operator: A java operator is a special symbol which is used to perform logical or mathematical operations on a data type or variable. In Java, an operator is a symbol that performs a specific operation on one or more operands (values or variables) and produces a result.Java Operator is a data or variable on which is the operation is to be performed.
Learn Best Java Operators List With Example in 2023
Learn Best Java Operators List With Example in 2023
    How Many Types of Operators are There in Java
    1. Arithmetic operators
    2. Comparison/Relational operators
    3. Logical operators
    4. Bitwise operators
    5. Ternary operator
    6. Assignment operators
    7. Conditional operators
    8. Increment and decrement operators

    1. Arithmetic operators: These operators perform basic mathematical operations, such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).

    2. Comparison/Relational operators: These operators compare two values and return a Boolean result, such as equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=).

    3. Logical operators: These operators perform logical operations, such as and (&&), or (||), and not (!).

    4. Bitwise operators: These operators perform operations on the individual bits of a number, such as and (&), or (|), xor (^), complement (~), left shift (<<), and right shift (>>).

    5. Ternary operator: This operator takes three operands, and is used as a shorthand for an if-else statement, it's written as "?:"

    6. Assignment operators: These operators are used to assign a value to a variable.

    7. Conditional operators: The conditional operator, also known as the ternary operator, is an operator in C++ that allows you to assign a value to a variable based on a certain condition.

    8. Increment and decrement operators: These operators increase or decrease the value of a variable by 1.

    Arithmetic Operators in java using methods

    Arithmetic Operator: A arithmetic operators are used to perform basic mathematical operations on numeric values. The following are the arithmetic operators in Java.

    1. Addition operator.
    2. Subtraction operator.
    3. Multiplication operator.
    4. Division operator.
    5. Modulus operator.

    Arithmetic Operator Table in Java Programming
    SymbolsOperationsExamples
    +Additionx+y
    -Subtractionx-y
    *Multiplicationx*y
    /Divisionx/y
    %Modulusx%y

    Arithmetic Operators in java Simple Program

    class Arithmetic

    {

    public static void main(String[] args)

    {

    int a=10;

    int b=3;

    System.out.println("Addition:"+(a+b));

    System.out.println("Subtraction:"+(a-b));

    System.out.println("Multiplication:"+(a*b));

    System.out.println("Division:"+(a/b));

    System.out.println("Modulus:"+(a%b));

    }

    }


    **********OUTPUT**********

    Addition:13

    Subtraction:7

    Multiplication:30

    Division:3.33

    Modulus:1


    Relational Operator in Java Language

    Relational Operator: A Java relational operator is used to compare two values and determine the relationship between them.
    1. Equal to.
    2. Not equal to.
    3. Greater than.
    4. Less than.
    5. Greater than or equal to.
    6. Less than or equal to.

    Relational Operator Table in Java Programming
    SymbolsOperationsExamples
    =Equalx=y
    !=Not Equal Tox!=y
    >Greater Thanx>y
    <Less Thanx<y
    >=Greater Than or Equal Tox>=y
    <=Less Than or Equal Tox<=y

    Relational Operators in Java with Example

    class Relational

    {

    public static void main(String[] args)

    {

    int a=10;

    int b=3;

    System.out.println("Equal To:"+(a=b));

    System.out.println("Greater Than:"+(a>b));

    System.out.println("Less Than:"+(a<b));

    System.out.println("Greater Than or Equal To:"+(a>=b));

    System.out.println("Less Than or Equal To:"+(a<=b));

    System.out.println("Not Equal To:"+(a!=b));

    }

    }


    **********OUTPUT**********

    Equal To:0

    Greater Than:1

    Less Than:0

    Greater Than or Equal To:1

    Less Than or Equal To:0

    Not Equal To:1


    Logical Operators in Java Definition

    Logical operators: Java logical operators are used to perform logical operations on Boolean (true or false) values. The following are the logical operators in Java:

    Logical AND (&&): This operator returns true if both opera

    1. AND (&&) operator: This operator returns true if both the operands are true, otherwise it returns false.

    2. OR (||) operator: This operator returns true if either of the operands is true, otherwise it returns false.

    3. NOT (!) operator: This operator returns true if the operand is false, and returns false if the operand is true.

    Logical Operator Table in Java Programming
    SymbolsOperationsExamples
    &&Logical ANDx&&y
    ||Logical ORx||y
    !Logical NOTx!y

    What are Logical Operators Explain with Examples

    class Logical

    {

    public static void main(String[] args)

    {

    int a=10;

    int b=60;

    int c=40;

    if(a>b&&a>c)

    {

    System.out.println("a is greater");

    }

    if(b>a&&b>c)

    {

    System.out.println("b is greater");

    }

    if(c>a&&c>b)

    {

    System.out.println("c is greater");

    }

    }

    }


    **********OUTPUT**********

    b is greater


    Bitwise Operators in Java

    Bitwise operators: A Java, bitwise operators are used to perform operations on the individual bits of an integer value. The following are the bitwise operators in Java:

    1. Bitwise AND (&) operator: This operator performs a bitwise AND operation on two operands. It returns 1 if both the operands are 1, and returns 0 otherwise.

    2. Bitwise OR (|) operator: This operator performs a bitwise OR operation on two operands. It returns 1 if either of the operands is 1, and returns 0 otherwise.

    3. Bitwise XOR (^) operator: This operator performs a bitwise exclusive OR operation on two operands. It returns 1 if either of the operands is 1, but not both, and returns 0 otherwise.

    4. Bitwise NOT (~) operator: This operator performs a bitwise NOT operation on an operand. It inverts all the bits of the operand.

    5. Bitwise left shift (<<) operator: This operator shifts the bits of an operand to the left by a specified number of positions.

    6. Bitwise right shift (>>) operator: This operator shifts the bits of an operand to the right by a specified number of positions.

    Bitwise Operator Table in Java Programming
    SymbolsOperationsExamples
    &Bitwise ANDx&y
    |Bitwise ORx|y
    ^Bitwise XORx^y
    ~Bitwise NOTx~y
    <<Bitwise LEFT SHIFTx<<2
    >>Bitwise RIGHT SHIFTx>>2

    Bitwise Operator in Java with Example

    class Bitwise

    {

    public static void main(String[] args)

    {

    int a=5;

    int b=3

    System.out.println("Bitwise AND Operator:"+(a&b));

    System.out.println("Bitwise OR Operator:"+(a|b));

    System.out.println("Bitwise Shift Right Operator:"+(a>>2));

    System.out.println("Bitwise Left Shift Operator:"+(a<<2));

    System.out.println("Bitwise XOR Operator:"+(a^2));

    }

    }


    **********OUTPUT**********

    Bitwise AND Operator:1

    Bitwise OR Operator:7

    Bitwise  RIGHT SHIFT Operator:1

    Bitwise  LEFT SHIFT Operator:20

    Bitwise  XOR Operator:7


    From the Following Which is an Assignment Operator

    Assignment operators: A Java, assignment operators are used to assign a value to a variable. The following are the assignment operators in Java:

    Compound assignment operators: These operators are used to perform an operation and assign the result to a variable in a single statement. The compound assignment operators are:

    1. Addition assignment operator(+=): This operator adds the right operand to the left operand and assigns the result to the left operand.

    2. Subtraction assignment operator(-=): This operator subtracts the right operand from the left operand and assigns the result to the left operand.

    3. Multiplication assignment operator(*=): This operator multiplies the left operand by the right operand and assigns the result to the left operand.

    4. Division assignment operator(/=): This operator divides the left operand by the right operand and assigns the result to the left operand.

    5. Modulus assignment operator(%=): This operator calculates the remainder when the left operand is divided by the right operand and assigns the result to the left operand.

    Assignment Operator Table in Java Programming
    SymbolsOperationsExamples
    +=Additionx+=y or x=x+y
    -=Subtractionx-=y or x=x+y
    *=Multiplicationx*=y or x=x+y
    /=Divisionx/=y or x=x+y
    %=Modulusx%=y or x=x+y

    Assignment Operators in Java with Example Programs

    class Assignment

    {

    public static void main(String[] args)

    {

    int a=5;

    System.out.println("Assignment Addition:"+(a+=2));

    System.out.println("Assignment Subtraction:"+(a-=2));

    System.out.println("Assignment Multiplication:"+(a*=2));

    System.out.println("Assignment Division:"+(a/=2));

    System.out.println("Assignment Modulus:"+(a%=2));

    }

    }


    **********OUTPUT**********

    Assignment Addition:7

    Assignment Subtraction:5

    Assignment Multiplication:10

    Assignment Division:5

    Assignment Modulus:1


    Increment and Decrement Operators in Java

    Increment and decrement operators: A Java, there are two increment operators: ++ and --. The ++ operator increases the value of a variable by 1, while the -- operator decreases the value of a variable by 1.

    Pre increment and Post increment Operator in C examples
    SymbolsOperationsExamples
    ++Pre-Incrementx++
    --Pre-Decrementx--
    ++Post-Increment++x
    --Post-Decrement--x

    Increment and Decrement Operators in Java with Example

    class Learncoding

    {

    Public static void main(string[] args)

    {

    int a=5;

    int b=10;

    System.out.println("Increment Operator:"+(++a));

    System.out.println("Decrement Operator:"+(--b));

    }

    }


    **********OUTPUT**********

    Increment Operator:6

    Decrement Operator:9


    What is the use of conditional operator in java

    Conditional Operator: The conditional operator, also known as the ternary operator, is an operator in Java that allows you to assign a value to a variable based on a certain condition. It is written as "condition ? value1 : value2", and it works as follows:

    1. First, the condition is evaluated.
    2. If the condition is true, the operator returns value1.
    3. If the condition is false, the operator returns value2.

    Increment and Decrement Operators in Java with Example

    class Learncoding

    {

    Public static void main(string[] args)

    {

    int a=5;

    int b=10;

    int max;

    max=a>b?a:b;

    System.out.println(" Greater Value is:"+max);

    }

    }


    **********OUTPUT**********

    Greater Value is:10



    Post a Comment

    0 Comments