Logical operator logic operator and (&&) ?? or (||) NOT (!) Get a boolean value, and they can only be used on Boolean. Boolean in logical expressions cannot be replaced using values similar to C / C . Note that Boolean is used in a point where String will appear, and its value will automatically convert to an appropriate text form, and if the basic data type of 2 comparisons is different, it is also possible to compare ~ for example 10 and 10.0d, result is also Will return TRUE. Short-circuit verification This means that some statements in logical expressions may cause some statements that have not been judged because of the logical operator, as long as everyone is careful, master is nothing wrong with it ~
The bit operator operator allows you to operate individual BIT bits in the basic data type, remember is an integer basic data type! The operator is directly generated by 0 and 1, directly for hardware, so some people say that Java cannot control the underlying hardware. This statement is incorrect. You can directly control hardware ~ It seems like ASM. When And (&) will be 1 when 2 input is 1, generate an output bit 1, otherwise 0; or (|) An arbitrary one is 1 when there is one input bit, generate an output bit 1, When the 2 input bits are 0, the output is 0; XOR (^) will have an output bit 1 when there is only one input bit to 1, and only one input bit is 1; NOT (~) is also called "one complement operation ", Is a one-dollar operator (other 2 yuan budget), he only accepts one quoter and produces a reverse bit. Note that the bit operator and logical operator are very icing. But they are different, I have seen a recruitment topic, which gives you the differences, except for '~', any bit operator can be used with assignment operators = number, similar to = Boolean, you can perform any one of the operators outside of NOT; for Boolean, the only difference between the bit operator and the logical operator is that the bit operator does not do short circuit, and finally Boolean is unable to do. Operation. The displacement operator displacement operator is also used to operate, and it is also possible to function on the integer basic data type in Java using completion of the binary number. In the complement indication, the highest is the symbol bit, the positive symbol bit is 0, the negative number symbol bit is 1, the completion of the completion is as follows: For positive, the highest bit is 0, the remaining points represent the number of binary numbers of the value itself; for negative numbers, the absolute value of the number is bitten Reverse, then the number of complements are obtained for the entire number 1. Such as -1 complement is 11111111, the absolute value of the absolute value is 00000001, and the reverse 11111110 is used, plus 1,1111111
The left shift operator (<<) will move left to left, and the number of bits of migration is determined by the right operand (after left shift, the low speed is 0) a = a << 2, so that the respective binary position of A Bit, right to supplement 0, if a = 00001111, a << 2 = 00111100, the high-left shifted bit is discarded without generating an overflow, the left shift one is equivalent to multiplying 2, using this method Implementing multiplication, it is much faster than multiplication, so some companies have such questions on the efficiency topic. Right shift operators (>>) will cause left operation to migrate, the number of digits of migration is determined by the right operand, facing the migration with the active noise, and the right-shifted operator will first use a called symbol extension. Measures: If the original value is positive, the high level is 0; if the original value is negative, the high level is added. In addition, Java has also added a right-shifted operation operator (>>) with a fixed number (>>): zero expansion measures: no matter whether the original value is or negative. I will make up at the high level. If the displacement object you operate is char, byte, short, when the displacement is made, it will be upgraded to int, and the displacement is performed, and of course the result is also int. The number of displacements in the displacement operation is useful for int type data, only 5 BIT bits of the low position are useful. For long, only 6 BIT bits of the low position are useful. The displacement operator is the same as other operators, but it can be used with =, but when there is a no-lane from >> = time in Byte and SHORT, there is a problem, because they will be upgraded to Int, then Right movement, then assign the value, but when they assign the value, the high level of the capacity of their capacity will be cut, it will produce a very strange number -1.
Public class test {public static void main (string args []) {INT i = -1; long L = -1; short s = -1; byte b = -1; I >>> = 10; system.out. Println (i); // 1 l >>> = 10; System.out.Println (L); // 2 s >>> = 10; system.out.println (s); // 3 b >>> = 10; system.out.println (b); // 4 b = -1; system.out.println (b >>> 10); // 4}} answer is it? 4194303, 18014398509481983, -1, -1 4194303 It is necessary to pay attention to this answer because the results after the fourth shift did not pass back B, so the correct answer can be displayed. The reason why this answer is the same, because B is upgraded into int b. So the answer and INT i are the same! The IF-ELSE Trimer This seems to be the only 3 yuan operator in Java, huh, huh ~ His format is Boolean-EXP? Value1: Value2 If the Boolean-Exp is determined by true, Value1 is executed, if false, execute the value2, this and the IF-ELSE statement is the same ~ But he wants to be refined than if-else statement, and the efficiency of the execution He is high! It should be noted that the statement in Value2 is to bring; the number, and cannot put it in system, out.println (); Not the control program process that IF-ELSE can implement. The comma operator is in Java, the only place to play; the operator is where the operator is in the For loop, this we will tell the Operator this problem applied to the string, I am in my "Java beginners easy to appear operators. The problem has been mentioned ~ in Java, if the number appears before String, the operation is the operation, and if the String appears, the character connection is performed, for example
Public class test {public static void main (string args []) {INT x = 1, y = 2, z = 3; string s = "string"; system.out.println (x y z s); System.out.println (s x y z); system.out.println (x y s z);}} Show 6String String123 3String3 ?? Transformation operator transformation is classified into 2 categories, automatic conversion and Forced conversion, automatic conversion is the automatic broadcation conversion, such as B 1 of the BYTE type, the system automatically converts his Byte type to int type, you can use byte b = b 1; see if you know The system will tell you Possible Loss of Precision, because when you add 1, the value of B is already int type, you can't assign a value back B, the system operates on the data type smaller than INT The value will be upgraded to int, and it will be upgraded to long when it is running with the long, and this is pushed. The so-called forced conversion is that you tell the compiler, I know that B is an int type but his expression value does not exceed the range of byte, you can rest assured that it is this: b = (BYTE) (B 1); he will narrow the intimate, but if you have the value of your calculation is greater than the original type of expression, you still have to force the conversion, and the memory overflow has occurred, then the overflow BIT bit will be abandoned, the data loss occurred phenomenon. Java only allows type conversion of basic data types other than Boolean, this is in general, when you put a constant in the program, the compiler knows what type is going to make him However, sometimes we can use some special characters to guide constants to guide the normal judgment of the compiler. After the constant value, add L / L refer to the long type, add f / f finger Is a float type, D / D refers to a Double type. The expression method of hexadecimal is to start with 0x / 0x, and the octal is starting with 0, but the binary expression method is not provided in Java, you need to pay attention to the sixteen maximum of these types that can be expressed.
Char 0xfffff ????? byte 0x7f ??????? short? 0x7fff ?? int? 0x7fffffffF
Java does not talk about the priority or that sentence, when it is unclear, add parentheses ~ 嘿嘿 ~ Nor need to remember those cumbersome priorities ~ the last point: When 2 the most large INT The abnormality caused by overflow, Java will not be reported in the compile period or the running period ~ this should be a small bug for him ~