1. Use the java Operator
+,-, *, \, = Almost all operators can only operate on the primary type. The only exception is "=" "="! = "Can operate on the main type, string supports" + "" + ="
2. Assignment
The assignment of the primary data type is very direct. Because the primary data type contains the actual value rather than the actual value handle, when the object is assigned a value, assign a value to another place. Assume that the primary type is a = B. If a is modified, the value of B is not affected;
If an object is assigned a value, the operation between objects is actually a handle operation. The object is assigned a value, and a handle is assigned to another place. C = D. If c changes, d will also change;
3. Relational operators
Relational operators generate a Boolean result. They evaluate the relationship between calculation object values. If the link is true, the relational expression generates true (true). If the link is not true, false (false) is generated ). Relational operators include less than (<), greater than (>), less than or equal to (<=), greater than or equal to (> =), equal to (=), and not equal (! = ). Equals and not equals apply to all built-in data types, but other comparisons do not apply to boolean types.
4. logical operators
Logical operators AND (&), OR (|), and not (!) Generate a Boolean value (true or false) based on the Logical Relationship of the independent variable. The following example shows how to use relational and logical operators.
1. Short Circuit
When operating logical operators, we will encounter a situation called "Short Circuit. This means that the logic of the expression is evaluated only when the true or false conclusion of the entire expression is obtained. Therefore, all parts of a logical expression may not be evaluated:
//: ShortCircuit. java
// Demonstrates short-circuiting behavior
// With logical operators.
Public class ShortCircuit {
Static boolean test1 (int val ){
System. out. println ("test1 (" + val + ")");
System. out. println ("result:" + (val <1 ));
Return val <1;
}
Static boolean test2 (int val ){
System. out. println ("test2 (" + val + ")");
System. out. println ("result:" + (val <2 ));
Return val <2;
}
Static boolean test3 (int val ){
System. out. println ("test3 (" + val + ")");
System. out. println ("result:" + (val <3 ));
Return val <3;
}
Public static void main (String [] args ){
If (test1 (0) & test2 (2) & test3 (2 ))
System. out. println ("expression is true ");
Else
System. out. println ("expression is false ");
}
}///:~
Each test compares the independent variables and returns true or false values. It does not display information related to what is to be called. The test is performed in the following expression:
If (test1 (0) & test2 (2) & test3 (2 ))
Naturally, you may think that all three tests will be executed. But I hope the output results won't surprise you:
If (test1 (0) & test2 (2) & test3 (2 ))
The first test generates a true result, so the expression evaluation continues. However, the second test produces a false result.
This article is from "Zhao Zhijun's blog"