Java Hardening Chapter (i)---new features of Java 1.5

Source: Internet
Author: User

New features of Java1.5

1. Tips for using shortcut keys

Shortcut key location: General->keys, set the alt+/key (d: Content a will be searched out) When prompted, to notice the alt+/key to remove the original binding relationship, direct input alt+/can find its binding relationship, You can also use the Remove binding button when you delete a bound relationship.

1, display system prompt: alt+/

2, program code automatic typesetting: ctrl+shift+f (JSP file is all reflow, Java files can be selected code rearrangement)

3, automatic import of the required categories: ctrl+shift+o (note and ctrl+shift+m difference)

4. View the original code of Use Category: Ctrl + left mouse button click (Link Entry)

5. Annotate the selected text: ctrl+/(seldom used later)

6. Uncomment the selected text: Ctrl + \

7, the scene switch: Ctrl+f8

8. Save All Files: Ctrl+shift+s

9. Close all Files: Ctrl+shift+f4

10. Jump to the specified line: ctrl+l (it works well when debugging)

11. Find Next: Ctrl+k

12. List the structure of the current file: Ctrl+f3/ctrl+o

13. List the inheritance structure of the class: Ctrl+t (useful for familiarity with unfamiliar system classes)

14. The original code of the method or class: F3 (This will not be introduced)

15. Method Structure of methods in class: F4

16. Copy the selected code: ctrl+alt+ (arrow)

17, the current line insert one line: Ctrl+shift+enter

18. Convert all selected letters to lowercase: ctrl+shift+y

19. Convert all selected letters to uppercase letters: CTRL+SHIFT+X

20. Connect the selected switch: Ctrl

21, search All files, contains keywords: ctrl+h (very useful)

22, System assistance or code hints and supplements: alt+/(most like this:))

23. Find the other half bracket: ctrl+shift+p

24, re-organize the imported package (import only the required packages, not required will be automatically removed): Ctrl+shift+m (note and ctrl+shift+o distinguish)

25, edit box and other window maximization: Ctrl + M

26, the editor's fallback, forward, toggle: Alt + Left and right arrows, Ctrl + F6

27. File Rename: F2

28. Refresh: F5

29. Refactoring: Ctrl+shift+r

2. Setting the Code template location: Java->editor->templates

3. Static Import

Import statements can be imported into a class or all classes in a package

Import Static statement Imports a static method or all static methods in a class

Syntax Examples:

Import Staticjava.lang.Math.sin;

Import static java.lang.math.*;

Note: A classmate once the problem: will Javac inadvertently changed to 1.4, the results of static import and other jdk1.5 features are reported wrong.

4. Variable parameters

Features of variable parameters:

A) can only appear at the end of the parameter list;

b) ... Between the variable type and the variable name, there are no spaces before and after it can be;

c) When invoking a method of a mutable parameter, the compiler creates an array for the mutable parameter implicitly, accessing the mutable parameter as an array in the method body.

5. Enhanced for Loop

Grammar:

For (type variable name: Collection variable name) {...}

Precautions:

The iteration variable must be defined in the ()!

A collection variable can be an array or a collection class that implements the Iterable interface

Example:

public static int Add (Intx,int ... args) {

int sum = x;

for (int Arg:args) {

sum + = arg;

}

return sum;

}

6. Automatic unpacking and boxing of basic data types

Automatic Boxing:

Integer NUM1 = 12;

Automatic unpacking:

SYSTEM.OUT.PRINTLN (NUM1 + 12);

Object caches for base data types:

Integer NUM1 = 12;

Integer num2 = 12; This piece is equal, <=127 is true.

System.out.println (NUM1 = = num2);

Integer num3 = 129; This block is not equal, because it is an object

Integer NUM4 = 129;

System.out.println (num3 = = NUM4);

Integer NUM5 = integer.valueof (12);

Integer NUM6 = integer.valueof (12); The truth of this piece is ibid.

System.out.println (num5== num6);

Note: The range of auto-boxing and unpacking: between -128~+127.

Because the numeric range is in: (-128 to 127) the object cache of the data type.

The difference between a simple type and a package type:

The wrapper class can be equal to NULL to avoid the two semantics of the number 0 o'clock.

Integer I=null;int ii=i;

Throws an Nullexception exception, which is equivalent to Intii=i.intvalue ();

enjoy meta-mode (flyweight): There are many small objects that have many of the same properties that make these same attributes the same object, called the internal state. The parameters that turn those different attributes into methods are called external states.

7. Enumeration

Enumeration is to make a variable of a type only one of several fixed values, otherwise, the compiler will error. Enumeration allows the compiler to control the illegal values that are filled out in the source program at compile time, which is not possible in the development phase of normal variables.

Enumerations are equivalent to a class, which can also define construction methods, member variables, common methods, and abstract methods.

The enumeration element must be at the very beginning of the enumeration body, and a semicolon separated from the other members after enumerating the list of elements. The compiler reports an error by placing the member method or variable in the enumeration before the enumeration element.

Enumeration with constructed methods

The construction method must be defined as private

If you have more than one construction method, how do you choose which construction method?

The enumeration elements, like the effect of Mon and Mon (), call the default constructor method.

Enumeration with methods

Defining enumerations Trafficlamp

Implementing the normal Next method

Implement the abstract next method: Each element is an instance object generated by the subclass of the enumeration class, which is defined in a manner similar to an inner class.

To increase the construction method on the representation time

When an enumeration has only one member, it can be implemented as a single instance.

Write enumeration steps and tricks with abstract methods:

1. Enumtrafficlamp{red,green,yellow}

2. Enumtrafficlamp{red,green,yellow;public abstract Next ();}

3.enumtrafficlamp{red{},green{},yellow{};p ublic abstract next ();}

4. Populate the next method in each {}.

Java Hardening Chapter (i)---new features of Java 1.5

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.