My Thinking in Java Learning Notes (IV)

xiaoxiao2021-03-06  123

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 shift, then assign the value, but when they assign the value, the high level of their capacity will be intercepted, 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 Need to pay attention to this answer, because of the fourth shift The resulting result 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 is the same as INT i! 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 (); the statement like the 3 yuan operator is his computing result value 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 there is a string, the character connection is executed, such as 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 system automatically When converting, for example, B 1 of the Byte type, the system will automatically turn 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 to B, and the system will increase their value to int when calculating the system than the intimate data type than INT, and It will be upgraded to long when computing with the long, and so on. 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 started with 0, but the binary expression method is not available in Java. You need to pay attention to the hexadecimal maximum char 0xfff that can be expressed in these types. ????? byte 0x7f ??????? short? 0x7fff ?? int? 0x7fffffff java does not have a Sizeof operator talk about priority or that sentence, plus parentheses ~ 嘿嘿 ~ you don't need to remember those cumbersome The priority is the last point: when the overflow of the 2 most large INT occurs, Java will not report in the compile period or the period of time. This should be a small bug. the ~

转载请注明原文地址:https://www.9cbs.com/read-125904.html

New Post(0)