Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
FAQs Support
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

Java Operators

Arithmetic Operators

OperatorNameExampleResult
+Addition5 + 38
-Subtraction5 - 32
*Multiplication5 * 315
/Division10 / 33 (integer division)
%Modulus10 % 31
++Incrementa++a = a + 1
--Decrementa--a = a - 1

Relational & Logical Operators

CategoryOperatorMeaning
Relational==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal
Logical&&AND — true if both operands are true
||OR — true if at least one operand is true
!NOT — inverts the boolean value
Arithmetic, Relational & Logical
public class Operators {
    public static void main(String[] args) {
        int a = 10, b = 3;

        // Arithmetic
        System.out.println(a + b);   // 13
        System.out.println(a - b);   // 7
        System.out.println(a * b);   // 30
        System.out.println(a / b);   // 3  (integer division)
        System.out.println(a % b);   // 1

        // Relational
        System.out.println(a > b);   // true
        System.out.println(a == b);  // false

        // Logical
        boolean x = true, y = false;
        System.out.println(x && y);  // false
        System.out.println(x || y);  // true
        System.out.println(!x);      // false
    }
}

Bitwise Operators

OperatorNameExample (a=5, b=3)Result
&Bitwise AND5 & 3 → 0101 & 00111 (0001)
|Bitwise OR5 | 3 → 0101 | 00117 (0111)
^Bitwise XOR5 ^ 3 → 0101 ^ 00116 (0110)
~Bitwise NOT~5-6
<<Left shift5 << 110
>>Right shift5 >> 12

Ternary & instanceof Operators

Ternary, Assignment & instanceof
public class MoreOperators {
    public static void main(String[] args) {
        // Ternary: condition ? valueIfTrue : valueIfFalse
        int age = 20;
        String status = (age >= 18) ? "Adult" : "Minor";
        System.out.println(status);  // Adult

        // Compound assignment operators
        int n = 10;
        n += 5;   // n = n + 5  → 15
        n -= 3;   // n = n - 3  → 12
        n *= 2;   // n = n * 2  → 24
        n /= 4;   // n = n / 4  → 6
        n %= 4;   // n = n % 4  → 2
        System.out.println("n = " + n);  // 2

        // instanceof — checks if an object is an instance of a class
        String str = "Hello";
        System.out.println(str instanceof String);   // true
        System.out.println(str instanceof Object);   // true (String extends Object)

        Object obj = "World";
        if (obj instanceof String s) {  // pattern matching (Java 16+)
            System.out.println("Length: " + s.length());
        }
    }
}

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.