Operators in Java – B.
Tech Exam Notes
Introduction
In Java, operators are special symbols used to perform operations on variables and values.
Operators allow programmers to manipulate data and perform calculations, comparisons, and
logical operations in programs.
Types of Operators in Java
Operator Type Examples Description
Arithmetic +, -, *, /, % Perform mathematical calculations
Relational ==, !=, >, <, >=, <= Compare two values
Logical &&, ||, ! Combine or invert boolean conditions
Assignment =, +=, -=, *=, /= Assign values to variables
Unary ++, --, ! Operate on a single operand
Bitwise &, |, ^, ~ Perform bit-level operations
Ternary ?: Conditional operator returning one of two values
1. Arithmetic Operators
• Used to perform mathematical operations.
• Example: int sum = a + b;
2. Relational Operators
• Used to compare two values.
• They return a boolean result (true or false).
3. Logical Operators
• Used to combine multiple conditions.
• Commonly used in decision-making statements like if and loops.
4. Assignment Operators
• Used to assign values to variables.
• Example: x += 5 means x = x + 5.
Advantages of Operators
• Allow efficient data manipulation.
• Reduce code complexity.
• Enable mathematical and logical computations.
Conclusion
Operators are essential elements of Java programming. They allow developers to perform various
operations on data, making programs functional and efficient.