filmov
tv
Java Programming Tutorial | Java Operators | Unary & Assignment Operator
![preview_player](https://i.ytimg.com/vi/xX8liOqGfEk/maxresdefault.jpg)
Показать описание
Welcome to our Java programming tutorial series! In this video, we'll explore the essential assignment and unary operators in Java. These operators are fundamental for manipulating and assigning values to variables in your Java programs.
Unary Operators in Java:
1. Unary Plus (+):
It indicates a positive value. It doesn't change the value of the operand.
Example: +a (if a is 5, +a is also 5)
2. Unary Minus (-):
It negates the value of the operand.
Example: -a (if a is 5, -a is -5)
3. Increment (++):
Increases the value of the operand by 1.
There are two types of increment operators:
Pre-increment (++a): Increments the value of a by 1 before using it in an expression.
Post-increment (a++): Uses the current value of a in an expression, then increments it by 1.
4. Decrement (--):
Decreases the value of the operand by 1.
There are two types of decrement operators:
Pre-decrement (--a): Decrements the value of a by 1 before using it in an expression.
Post-decrement (a--): Uses the current value of a in an expression, then decrements it by 1.
5. Logical Complement (!):
Inverts the value of a boolean expression.
Example: !bool (if bool is true, !bool is false)
6. Bitwise Complement (~):
Inverts each bit of its operand (i.e., 0 becomes 1 and 1 becomes 0). This is also known as bitwise NOT.
Example: ~a (if a is 5, ~a is -6 in binary form)
Assignment Operators
Basic Assignment Operator
= (Simple Assignment)
Assigns the value on the right to the variable on the left.
Example: a = 5; assigns the value 5 to the variable a.
Compound Assignment Operators
1. += (Addition Assignment)
Adds the right operand to the left operand and assigns the result to the left operand.
Example: a += 5; is equivalent to a = a + 5;.
2. -= (Subtraction Assignment)
Subtracts the right operand from the left operand and assigns the result to the left operand.
Example: a -= 5; is equivalent to a = a - 5;.
3. *= (Multiplication Assignment)
Multiplies the left operand by the right operand and assigns the result to the left operand.
Example: a *= 5; is equivalent to a = a * 5;.
4. /= (Division Assignment)
Divides the left operand by the right operand and assigns the result to the left operand.
Example: a /= 5; is equivalent to a = a / 5;.
5. %= (Modulus Assignment)
Takes the modulus of the left operand by the right operand and assigns the result to the left operand.
Example: a %= 5; is equivalent to a = a % 5;
👍 If you found this video helpful:
Give us a thumbs up and share it with your friends!
Comment below if you have any questions or suggestions for future tutorials.
Thank you for watching! Don't forget to subscribe and hit the bell icon to get notified about our latest videos.
Unary Operators in Java:
1. Unary Plus (+):
It indicates a positive value. It doesn't change the value of the operand.
Example: +a (if a is 5, +a is also 5)
2. Unary Minus (-):
It negates the value of the operand.
Example: -a (if a is 5, -a is -5)
3. Increment (++):
Increases the value of the operand by 1.
There are two types of increment operators:
Pre-increment (++a): Increments the value of a by 1 before using it in an expression.
Post-increment (a++): Uses the current value of a in an expression, then increments it by 1.
4. Decrement (--):
Decreases the value of the operand by 1.
There are two types of decrement operators:
Pre-decrement (--a): Decrements the value of a by 1 before using it in an expression.
Post-decrement (a--): Uses the current value of a in an expression, then decrements it by 1.
5. Logical Complement (!):
Inverts the value of a boolean expression.
Example: !bool (if bool is true, !bool is false)
6. Bitwise Complement (~):
Inverts each bit of its operand (i.e., 0 becomes 1 and 1 becomes 0). This is also known as bitwise NOT.
Example: ~a (if a is 5, ~a is -6 in binary form)
Assignment Operators
Basic Assignment Operator
= (Simple Assignment)
Assigns the value on the right to the variable on the left.
Example: a = 5; assigns the value 5 to the variable a.
Compound Assignment Operators
1. += (Addition Assignment)
Adds the right operand to the left operand and assigns the result to the left operand.
Example: a += 5; is equivalent to a = a + 5;.
2. -= (Subtraction Assignment)
Subtracts the right operand from the left operand and assigns the result to the left operand.
Example: a -= 5; is equivalent to a = a - 5;.
3. *= (Multiplication Assignment)
Multiplies the left operand by the right operand and assigns the result to the left operand.
Example: a *= 5; is equivalent to a = a * 5;.
4. /= (Division Assignment)
Divides the left operand by the right operand and assigns the result to the left operand.
Example: a /= 5; is equivalent to a = a / 5;.
5. %= (Modulus Assignment)
Takes the modulus of the left operand by the right operand and assigns the result to the left operand.
Example: a %= 5; is equivalent to a = a % 5;
👍 If you found this video helpful:
Give us a thumbs up and share it with your friends!
Comment below if you have any questions or suggestions for future tutorials.
Thank you for watching! Don't forget to subscribe and hit the bell icon to get notified about our latest videos.