1. Each overloaded method must have a unique list of parameter types . (The parameter order is different enough to distinguish two methods, but it is not recommended to make the code difficult to maintain.) )
2. When overloading a method, the actual data type is promoted to the type accepted by the method if the type of the passed data type (the actual parameter type) is less than the parameter type declared in the method, if the method that can be overloaded is only different. The char type is slightly different, and if you cannot find a method that exactly accepts the char parameter, the char is promoted directly to the int type. (P81)
If the actual parameter passed in is large , the narrowing conversion is performed through the type conversion. If you do not do this, the compiler will make an error. That is, the type conversion, after the parameter passed in.
3. If you do not provide any constructors, the compiler will think "you need a constructor, let me make one for you"; but if you have written a constructor, the compiler will think, "Ah, you've written a constructor, so you know what you're doing; you deliberately omitted the default constructor. That is, the compiler will not create a default constructor for you at this time.
4. The This keyword can only be used inside a method, representing a reference to the "object that called the method".
5. Multiple constructors may be written for a class, and sometimes you might want to call another constructor in one constructor to avoid duplicate code, which can be done using the This keyword. At this point, in the constructor, if you add a parameter list to this, an explicit call to a constructor that conforms to this list of parameters is generated. Such as:
public class a{
A (String s) {
}
A (String s,int i) {
This (s);//equivalent to A (s);
}
}
However, the following rules need to be observed:
(1) Although you can call a constructor with this, you cannot call two constructors in a constructor, that is, you can invoke at most one constructor in a constructor;
(2) The constructor call must be placed at the very beginning, or the compiler will error;
(3) In addition to the constructor, the compiler prohibits invoking the constructor in any other method.
6. The static method is the method without this. A non-static method cannot be called inside the static method, of course, which is not entirely impossible: if you pass a reference to an object into a static method and then through that reference, you can invoke the non-static method and access the non-static data member.
7. Principles of garbage collection compliance in Java:
(1) The object may not be garbage collected;
(2) Garbage collection is not equal to "destruction";
(3) Garbage collection is only related to memory.
If the JVM is not running out of memory, it will not waste time doing garbage collection to recover memory.
8. In C + + you can create a local object (that is, created on the stack, which does not work in Java), and in Java you do not allow the creation of a local object, you must use new to create the object. ( Java objects are created on the heap and cannot be created on the stack )
9. Within the class, the order in which the variables are defined determines the order in which they are initialized. Even if the variable definitions are scattered between the method definitions, they will still be initialized before any methods (including constructors) are called.
10. Initialization of static objects precedes non-static objects, and static objects are initialized only once.
11. When declaring an array, the compiler does not allow the size of the specified array. That is: int a[10]; The compiler will make an error. The base data type values in the array elements are automatically initialized.
Switch and enum are great combinations.
Java Programming thought Learning (iii) initialization and cleanup