Knowledge Points: 1. Precedence of various operators 2. Operatorsone, arithmetic operators
1. Arithmetic operators:
Another easy way to do it
For example: j = j + I; can be written as j + = i; the same as J-= i;
1.2 Relational operators
The relational operator is used to compare operands, assuming the variable a=20,b=10:
1.3 Logical operators
Logical operators are used to describe and, or, non- logical relationships, assuming variable a=true,b=false:
1.4-bit operators
Bitwise operators can be applied to integer types, long types, integers, short integers, characters, and bytes. It acts on bits and performs bitwise operations. Bits operation specific look: How binary is doing bit arithmetic
Assuming integer variables a=60 (0011 1100) and variable b=13 (0000 1101), then:
1.5 Assignment operators
The assignment operator is used to assign a value to a variable , as follows:
1.6 Other operator _ conditional operators
The conditional operator, also known as a ternary operator, can be a special type of assignment operator that determines which values should be assigned to a variable. Grammar:
Variable x = (expression)? Value if True:value if False
"?" The left side of the number is the conditional expression ture or FALSE, if true assigns the left value of ":" to the variable to the left of "=", and false to the right of ":" to the variable to the left of "=".
Instance:
public class Test {public static void Main (String args[]) { int A, b; A = ten; b = (A = = 1)? 20:30; System.out.println ("Value of B is:" + B);//Result: Value of b is:30 b = (A = = 10)? 20:30; System.out.println ("Value of B is:" + b);//Result: Value of B is:20 }}
1.7 Other operator _instanceof operators
The instanceof operator is used only for object reference variables and checks whether the object is of a specific type (class or interface type). Grammar:
(Object reference variable) instanceof (class/interface type)
The result is true if the value on the left is of the same type as the class/interface type (containing the parent class) on the right.
Instance:
public class Test {public static void main (string args[]) { string name = "James"; Boolean result = name instanceof String; SYSTEM.OUT.PRINTLN (result);//Results: True }}
Example 2:
Class Vehicle {} public class Car extends Vehicle {public static void main (String args[]) {Vehicle a = new Car (); Boolean result = a instanceof Car; SYSTEM.OUT.PRINTLN (result);//Results: true}}
Second, priority
"Java Base-java operator"