Java operators in programming language
Java offers a robust operator environment. An operator is a symbol that instructs the computer to perform a specific logical or mathematical operation. The application uses operators to alter variables and data. Usually, they are included in mathematical or logical expressions.
The following categories can be used to group Java operators:
- Arithmetic Operators
2. Relational Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. Conditional operator
Arithmetic Operators
Addition, subtraction, multiplication, and division are the fundamental operations in mathematics used in Java programming.
On numerical data types, arithmetic operations are performed as anticipated.
Operators used in math can become overloaded.
Since they work with two operands, arithmetic operators are “Binary” operators.
Similar to how they are used in algebra, these operators are utilized in mathematical expressions.
Relational Operators
A relationship between two variables or integers is checked using relational operators.
Relational Operators return a “Boolean” value .i.e it will return true or false.
The majority of relational operators are used in “if statements” and looping statements to determine whether a condition is true or false.
Bitwise Operators
The integer types long, int, short, char, and byte can all be used with the various bitwise operators that Java defines.
Logical Operators
Java supports the following 3 logical operators.
The Assignment Operators
The assignment operator supported by Java is as follows
Conditional Operator
Conditional operators are used in Java to determine the desired outcome based on the condition and both conditions.
There are three types of conditional operators in java.
- Conditional AND
- Conditional OR
- Ternary Operator
Conditional AND
The operator is applied between two Boolean expressions. It is denoted by the two AND operators (&&). It returns true if and only if both expressions are true, else returns false.
Conditional OR
The operator is applied between two Boolean expressions. It is denoted by the two OR operators (||). It returns true if any of the expressions is true, else returns false.
Let’s create a Java program and use the conditional operator.
Conditional Operator Example. java
- public class Conditional Operator Example
2. {
3. public static void main (String args[])
4. {
5. int x=5, y=4, z=7;
6. System.out.println (x>y && x>z || y<z);
7. System.out.println ((x<z || y>z) && x<y);
8. }
9. }
Output
true false