-------------------- Android training, Java training, and hope to communicate with you! ----------------------
1. myeclipse TemplateCodeConfiguration
Window-> preferences
2 JDK 5.0 static Import
The import statement can be used to import a class or all classes in a package.
Import static statements to import a static method or all static methods in a class
Syntax example:
Import static java. Lang. Math. sin;
Import static java. Lang. Math .*;
3. Enhance the for loop and variable parameters
Problem: the number of parameters accepted by a method is not fixed, for example:
System. Out. println (countscore (2, 3, 5 ));
System. Out. println (countscore (1, 2, 3, 5 ));
Features of variable parameters:
It can only appear at the end of the parameter list. Remember this.
... It is located between the variable type and the variable name, and there are no spaces before and after it. When the variable parameter method is called, the compiler implicitly creates an array for the variable parameter, in the method body, you can access variable parameters in the form of arrays.
Syntax: For (type variable name: Set variable name ){... }
Note:
- Iteration variables must be defined in!
- Collection variables can be arrays or collection classes that implement the iterable interface.
Example:
Public static int add (int x, Int... ARGs ){
Int sum = X;
For (INT Arg: ARGs ){
Sum + = ARG;
}
Return sum;
}
4. Automatic box disassembly and metadata sharing (in jdk5.0)
Automatic packing: integer num1 = 12;
Automatic unpacking: system. Out. println (num1 + 12 );
Object Caching for basic data types:
Integer num1 = 12;
Integer num2 = 12; This one is equal,-128 <= num <= 127 is true (Here we use the enjoy meta mode flyweight)
System. Out. println (num1 = num2 );
Integer num3 = 129; this part is not equal because it is an object
Integer number4 = 129;
System. Out. println (num3 = num4); // false
Integer num5 = integer. valueof (12 );
Integer num6 = integer. valueof (12 );
System. Out. println (num5 = num6); // true
PS: The Meta design mode is also used in the string class: String S1 = "ABC"; string S2 = "ABC "; the shared element design pattern S1 and S2 are used to direct different referenced variables to the same object.