Last Updated: 28 May, 2022
Operators are special symbols that performs the specified operations. Each operator is responsible to perform some specific operation on variables or values and return a result. The operators are classified and listed according to precedence order.
Java supports the following types of operators:
In Java, Unary operators work with only one operand, It is used to perform operations like increment, decrement, negation, etc.
Let's breifly understand Unary Operators by given table
Operator Name | Operator Symbol | Description | Example | Equivalent Expression |
---|---|---|---|---|
Unary Plus | + | It is used to represent the positive value. | +a | a |
Unary Minus | - | It is used to represent the negative value. | -a | - |
Increment Operator | ++ | It increments the value of a variable by 1. | ++a or a++ | a=a+1 |
Decrement Operator | -- | It decrements the value of a variable by 1. | --a or a-- | a=a-1 |
Logical Complement Operator | ! | It inverts the value of a boolean variable. | !true | - |
Example 1 : Unary Plus, Minus and Logical Complement Operator
Output
num = 10
num = -10
flag = false
flag = true
Example 2 : Increment Operator and Decrement Operator
Output
x - 6
y - 6
a - 11
b - 10
x - 5
y - 5
a - 10
b - 11
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com