Java Unary Operators

In this tutorial you will learn about the Java Unary Operators and its application with practical example.

Java Unary Operators (post and pre)

In Java, ++ and — are know as increment and decrement operators respectively. These are unary operators it means they works on single operand. ++ adds 1 to operand and — subtracts 1 to operand respectively. When ++ is used as prefix(like: ++i), ++i will increment the value of i and then return it but, if ++ is used as postfix(like: i++), operator will return the value of operand first and then only increment it.

Operator Example Description
++ [prefix] ++a The value of a after increment
++ [postfix] a++ The value of a before increment
— [prefix] –a The value of a after decrement
— [postfix] a– The value of a before decrement

Example:-

When you run the above java program, you will see the following output.

Output:-

java_unary_operators_example

Recommended:-  Java Keywords and Identifiers
In this tutorial we have learn about the Java Unary Operators and its application with practical example. I hope you will like this tutorial.