Java high-tech myeclipse usage, static import, enhanced for, Automatic Disassembly box, and metadata Mode

Source: Internet
Author: User

-------------------- 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.