No matter what language you use, you end up with business logic. In object-oriented programming languages, business logic is implemented in methods. Therefore, it is necessary for beginners to understand the basics of completing the Java class method body. In this article, you will describe the two aspects that you must understand to write the method body: operators, Process Control.
The operators in Java can be grouped into 4 categories, depending on their functionality. The first thing to note is that the operators in Java are not overloaded. The 4-class operators are described below.
1. Arithmetic operator: +,-, *,/,%,++,--
An arithmetic operator is an operator that operates on the base data type, where it is easy to confuse/represent the exception, while% represents the remainder. Also note is the difference between the + +,--two self-subtraction operators, as shown in the following procedure.
Package com.csst.test;
public class Test1 {
/**
* @param args */public
static void Main (string[] args) {
//TODO Auto-genera Ted method stub
int i=0;
System.out.println (i++);
System.out.println (++i);
int j=0;
System.out.println (j--);
System.out.println (--J);
}
+ +,--After the variable, the first takes the value of the variable before the operation, as the return value of the expression, and then the operation. and + +,--If the variable is preceded by an operation, then the result of the operation is used as the return value of the expression. It should be noted that both before and after, for the variables involved in the operation of the variable itself, is a plus 1 or minus 1 of the operation, there is no difference, the difference is the value of the return value.
Arithmetic operators are all based on the basic data type, except for +, which can be used to connect two strings. Such as:
String s= "Hello" + "world";//string's value is Hello World
2, bitwise operator:&,|,^,~,<<,>>,>>>
Bitwise operators are operators that operate on binary numbers. and Operations & Operation rules are two are 1 is 1, or operation | The rule is that one is 1 is 1, the rule of the XOR or ^ is different is 1, the same is 0. The reverse operation ~ is 1 variable 0,0 to 1.
<<: Left shift operator, the rule is, throw off the corresponding digits of the high, in the corresponding vacancy of 0. Such as:
0110 1001 << 2 = 1010 0100
>>: The symbol right SHIFT, the rule for, throw off the corresponding digits of the low, if the shift before the highest one is 0, then in the corresponding high all 0, if the shift before the highest one is 1, then in the corresponding high all 1.
0110 1001 >> 2 = 0001 1010
1110 1001 >> 2 = 1101 1010
>>>: Unsigned Right shift, the rule is, throw off the corresponding number of digits low, in the corresponding vacancy of 0:
0110 1001 >>> 2 = 0001 1010
1110 1001 >>> 2 = 0001 1010
Note: The right shift operator is divided into symbols and unsigned, and the left shift does not have this distinction. Another shift left one is equal to 2, and the right one is the equivalent of dividing by 2, which is faster.