My Thinking in Java Learning Notes (3)

xiaoxiao2021-03-06  112

Chapter III Control Process Process

In the world of Java, the processing of objects and data is through operators, while choices and judgments are implemented by control statements.

2 uses of Java operator operators, 1, operators accept quotes, and generate new values, such as INT A = 1 1; 2, operators can also change the value of the operand, such as i ;

Most operators can act on top of the basic data type, but =, == ,! = Yes, they can act on any object.

Priority order

This is actually very headache! So I will never remember what operator's priority, plus parentheses in can't figure out, not only you look very clear, nothing is low, others can see your code is also clear.

Assignment and assignment

The meaning of assignment is to obtain the value on the right side of the operator (any constant, variable, can generate a value of the expression), and pass the value to the left, using the operator = because the basic data type is stored, the actual value, does not have a handle (You can also understand the pointer in me C ), a = b; this sentence is to pass the specific value to a variable, when you change A, the value of B does not change with your A Change, but when you operate the object, it is easy to appear and the opposite of the above phenomenon. When you actually operate, it is actually an object's handle, when you assign an object to another object,

Actually assigned a handle, for example

Class one {int I = 0;} Class Two {public static void main (string args []) {one O1 = new one (); one O2 = new one (); O1.i = 10; O2.i = 20 System.out.print ("O2.i =" O1.i); System.out.Println ("O2.i =" O2.I); O1 = O2; System.Out.Print ("O2. I = " O1.i); system.out.println (" o2.i = " o2.i); O1.I = 30; system.out.print (" o2.i = " O1.i) System.out.println ("O2.i =" O2.I);}} Class ONE is created in Two, and is assigned to 10 and 20 separately. Output is of course 10 and 20, then assign O2 to O1, the output is definitely 20 and 20, but the wonderful thing is generated when the value is assigned, when we change O1.i to 30, discovery Why is our O2.i become 30? We didn't change his value! This is because O1 and O2 contain the same handle. The original O1 stored handle is overwritten, the address refers to the same memory space as O2, and the memory space he originally pointed back is in an appropriate time. The recycling mechanism is for recycling. In fact, this process happens in the second assignment we don't have problems! The above phenomena is called alias, this is a special topic in Appendix A of Thinking in Java! If we don't want to happen this, we can use O1.i = O2.i to perform step 2, such a way of writing can ensure that the two objects are independent of each other, but this is not a good way to operate directly. Data within the object can cause confusion, and the idea of ​​OOP is contrary to the idea, and better methods are in Appendix A. Alias ​​problem when calling a function

Class one {INT i = 10;} class two {static void Hello (one O) {oi = 20;} public static void main (string args []) {one someone = new one (); system.out.println Someone.i); hello (someone); system.out.println (someone.i);}}

Our Java programs will create an instance object that names an O's ONE within the Hello () function of the Hello () function, which is used to accept the quotes passing in the outside world, but we use the above method, and it is actually Just a Someone handle, and the name of the name in Hello () called an O object of O object will also affect the i in someone outside the Hello survival space! It's really depressed! Mathematical operator

Here we must pay attention to a problem is that the result of the division of the integer will ignore the decimal part, notice that it is not all round! What is a brief operator? A brief operator is followed by an operator followed by a = number, which is used in all operators in Java. For example, the value of X 10 is given from the new assignment to x, you can use X = 10 simple form. Example of the specific mathematics operator, I don't give you, because this is very simple, and there is no difference in mathematics operations in our primary school.

One yuan operator negative (-) and positive ( ) are one yuan operator

Increment and decrementing increment ( ) and decreasing (-) They have 2 forms, one is a prefix ( i), one is a suffix (i ) need to note, these two methods are different, When using a prefix, it is the previous prefix, and then passes the value to i, then participate in the back operation, and use the suffix to participate in the calculation, then make the edible computation, for example

Public class test {public static void main (string args []) {INT i = 0; system.out.println ( i); system.out.println (i ); system.out.println (i);} } The answer is 1, 1, 2, advances, then put the value (1) The second display is to display the value of I (1), in the self-incision (2), but the self-added did not show because of self The added value participates in the next operation, which is the reason for the third display 2.

Relationship operator Note, I have written an article about the operator in my blog (

Http://blog.9cbs.com/maoerzuozuo) About operators

Regular places and answers, if you can answer all, then you are basically no problem in mathematical operators!

The logical operator is actually my most depressed place, because I can't remember what And not NOT represents.

Let's wait! I will go back to tap this evening! Tomorrow give you an article ~ Oh everyone, if there is any problem in the process of learning, can contact me like this.

E-mail

Molmd@163.net /163.com QQ: 31349283 We can learn together!

Welcome to my blog,

Http://blog.9cbs.com/maoerzuozuo has more learning content!

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

New Post(0)