[text]
1.String class and StringBuffer classes They are clasped by the string, but they have a biggest difference, that is. EG1:
... // omit some code string S1 = "you are hired!"; system.out.println (s1.replace ('h', 'f')); // use f to put the string H replaced system.out.println (S1); ... // omit Some Code Run Result: You Are Fired! You are Hired! Results Analysis: From the results, it can be seen that the value of S1 is not changed. And the first line of results is only the replacement of the screen content. EG2:
... // omit some code stringbuffer s2 = new stringbuffer ("Hello from Java!"); S2.Replace (6, 10, "to"); System.out.Println (S2); ... ... // omit Some Code Run Results: Hello to Java! Results Analysis: Obviously, the value of S2 has changed. 2. Bit logic and conditional logic first declare that in order to better distinguish between the logic, I will usually The logic said with a personal name is called conditional logic. They all have their operators, bit logic operators are: & (with operation), ^ (alternative or calculation), | (or calculation); conditional logic operators are: && (and), || (or). Bit logical operations are typically for two numbers, and the conditional logic is performed for two conditional expressions. In fact, the bit logic operator can achieve conditional operations, but at this time An important difference: When using the operator, regardless of the conditional expression on both sides of the operator is not established, it is not established, and the conditional logic operator is different. If the number of operands through the left can be made It is necessary to determine, then it will not calculate the number of operands on the right side, this is called short circuit. Tone less! And look at the example. EG1:
... // Omit Some Code Double Value = 0; IF (Value! = 0 && 1 / Value <1000) {System.Out.println ("The Value IS Not Too SMALL.");} else { System.out.println ("The value is to small.");} ... // omit Some Code Run Results: The value is to small. Result Analysis: The graphics should have an error in which the divisor is 0 But I just said that because the conditional logic operator is a short-circuit operator, obviously, value! = 0 is not established, immediately determines the statement after Else, so it will no longer judge 1 / Value <1000 If you don't understand, please see another example: EG2:
... // omit some code double int1 = 0, INT2 = 1, INT3 = 1; if (INT1! = 0 & (INT2 = 2) == 1) {} system.out.println ("INT2 = " INT2); if (INT1! = 0 && (INT3 = 2) == 1) {} system.out.println (" int3 = " int3); ... // omit some code run RESULTS: INT2 = 2.0 INT3 = 1.0 Results Analysis: I don't want me to analyze, you should understand it. 3. Example variables and class variables can store data in classes in classes - as instance variables and class variables The instance variable is subject to object, if you have two objects (ie, two instances of a class), the instance variable in each object is independent of the instance variable in another object; on the other hand, two objects Both variables point to the same data, and so that the same value is saved, in other words, the class variable is shared all objects in the class. Almost forgot, their differences, class variables are more than instance variables More static. EG: Class Data {public int INTDATA = 0; // Obviously, INTDATA is here example variable} public class exam {public static void main (string [] args) {data a, b; a = new data (); b = new data (); a.intdata = 1; system.out.println ("B.indata =" b.intdata);}} Run results: b.intdata = 0 results analysis: It can be seen Although A. Inddata has changed, it does not affect B.intData. But if INTDATA is declared in the Data class, it becomes a class variable in front of it (ie: public static int interive = 0; At this time, the operation result will be changed to: b.intdata = 1 This time the A.Intdata value changes the B.intData, in fact, both the objects A and B varies from the same data, all values Like, this is the role of class variables.
4. Example, class method, constructor method. We usually say that the method is an example method, just like a function in the C language, I don't have to say the specific method, here I mainly use it to distinguish between Method and constructor method. The biggest difference between class method and example method is that in the form of a similar method more static, in the usage, you do not have to create an object directly to call the class method (and the instance method must first create objects, then Pass the object call). EG:
Class address {static int Addem (int OP1, INTOP2) {RETURN OP1 OP2;}} public class xxf {public static void main (string [] args) {system.out.println ("Addem (2, 2) = " add.addem (2, 2));} // Directly use class name as object call class method} Note: You can also create objects, then call the method, then call the method, but then static is not Any meaning. Moreover, it is a way to initialize the data used to initialize the object. It is easy to create, just add a method with the same name as this class, do not need to add any access notes or return to the front. Type, additionally, the constructor can also transmit parameters as the method. EG:
Class Data {Private String Data1; // Declaring Data (String S) {DATA1 = S; / * The variable is initialized by receiving data. (Note: Can't declare the variables within the constructor, you must declare in advance.) * / PUBLIC STRING GETDATA () {Return Data1;}} public class xxf {public static void main (string [] args) {system.out.println (("i love you"). getData ()). / * Create a new object by passing the parameter call constructor, then obtain the data * /}} 5. Interface and class class is a specific type of specific object specification, we can create an object by creating an object Combine all components belonging to this class, and the interface can not do this. The interface is essentially a collection of constants and abstract methods. To use an interface, you need to implement this interface in the class, then use part of the class definition, write an interface Each method in the interface, the method in the interface is always public, abstract, constant in the interface is always public Static and Final, so there is no need to explain the properties for them. Because multiple inheritors are not supported in Java, similar functions can be implemented with interfaces, this is one of the important roles of the interface. EG: Interface Anyone // Defines an interface {Final Double Pi = 3.1416; void setNumber; int getNumber ();} interface annother // defines another interface {void setstring (String str); string getString (); } Class XXF IMPLEMENT Anyone, Anyother // Defines a class and uses two interface {int number; string str; public xxf () {} void setNumber (int Number) {this.number = number;} void setstring (String Str ) {this.str = Str;} void int getNumber ()} // can be an empty implementation. Void string getString () {}} // All methods declared in the interface must be implemented. (Of course No, but use the adapter or use abstract class)