The operator is used to accept one or more parameters and generate a new value. The Plus and unary positive sign (+), minus sign and unary minus (one), multiplication sign (*), Division sign (/), and assignment number (=) are similar to most programming languages.
The operator acts on the operand and generates a new value. In addition, some operators may change the value of the operand itself, which is called a "side effect." The most common use of operators that can change their operands is to produce side effects, but keep in mind that the values generated by using such operators are no different than those generated with operators with no side effects. Almost all operators can only manipulate "basic types". , but "=", "= =", and "! =" can manipulate all objects. String supports "+" and "+ =".
Priority level
When an expression has multiple operators, the calculation is based on the priority of the operator, first multiplication and then minus. The easiest way to do this is to use parentheses () to control the order of the operators.
The string type can be used with + to concatenate each string.
Assign value
Normal assignment: The assignment uses the operator "=", the right value is copied to the left, and the left value must be a definite variable. For example: a=8;
Object assignment: When we assign a value to an object, we really manipulate the reference to the object. If you assign an object to another object, the real Ruan is copying the reference from one place to another. This means that if c=b is used on the object, then both C and B point to the object that was originally only B. This is illustrated in the following example.
ClassBreakyizhan{int Y;}PublicStaticvoidMain(String[] Args){Breakyizhan C1=NewBreakyizhan(); Breakyizhan C2=NewBreakyizhan(); C1. Y=2; C2. Y=80; System. Out.println("1:c1. Y: "+c1. Y+", C2. Y: "+c2. Y);Objects C1 and C2 all point to C2 objects; Remember C1 and C2 are just a reference; C1=c2; System. Out.println("2:c1. Y: "+c1. Y+", C2. Y: "+c2//object C1 after the reference is overwritten, is lost, that is, the object referred to by C1 was "garbage collected", C1 now and C2 refers to the same object C1= 33; System.out. Println "3:C1. Y: "+c1+ +c2 /span>
The result is:
1: C12 . Y:802 80 . Y:803 33 . Y:33
This method of Java manipulation of objects is called "aliasing phenomenon", in order to avoid this phenomenon, it can be written: C1. Y=c2. Y
For more information, please visit: All Java operator parsing | Break Easy Station
Common operators for Java