New features of java1.5

Source: Internet
Author: User

New features of java1.5.

Java as a language, is produced by Sun, the language has its own grammatical norms. At the same time around the language there are some basic class library for everyone to use.

A programming language can simply be thought of as having two parts, one being the basic grammatical rules (including keywords) and the other being used to support the language
Some system-level access to the base Class library.

Therefore, a programming language can be updated continuously, upgrade the updated language may add new syntax specification.

java1.5 and java1.4 as different versions of the Java language, there are some differences:

So there are new features of java1.5 that need to be mastered:

1, java1.5 support static import (import static)

Static import (import static): Used to import a member of a class, or all members of a class.

Normal import: Used to import a class, or all classes in a package.

For example: import static java.lang.Math.abs;

2. java1.5 supports variable parameters
Implementation principle: The compiler implicitly creates an array to encapsulate the actual parameters and pass them to the mutable parameters. A mutable parameter is equivalent to an array reference.
You can use mutable parameters as array references in methods that contain mutable parameters.

Benefit: Eliminates the manual new object in the process of defining the actual parameters. Only a small class of overloaded cases (that is, the same type of parameters, and the number
Different).

Specification: A mutable parameter must be defined in the last parameter position of the parameter list.
"Data Type ... Name of parameter "

Example: Void method (int x,int ... args) {}

3. java1.5 supports enhanced for loop
Implementation principle: The underlying is essentially still implemented using iterators (iterator).

Spec: "For (data type variable name: Collection name (or an expression that returns a collection)}"
The variable name must be defined in for () and cannot be defined in another location.
The "collection name" must implement the Iterable interface.

Note: Arrays are also a collection. A fixed-length collection.

Example: for (int arg:args) {}


4. java1.5 supports automatic packing and unpacking of basic data types

Benefit: The conversion between the base data type and the object does not require manual operation and is automatically completed by the system.

Example: Integer IOBJ = 3;

Note: Numbers that are located between -128~127 (that is, numbers represented by a single byte) are encapsulated as objects (whether manually boxed or
Automatically boxed) is placed in the cache pool. When an object of that number is encapsulated again, no new object is created, and the
The object is fetched directly from the cache pool to be paid to the reference. For example: "Interger i2 = 4; Integer i3 = 5; ", I2 and i3 are the same reference, that is, the value
Same.

What is the enjoy meta design pattern:
When there are many small objects, their properties are mostly the same, only a few attributes are different, and these small objects are created and seldom change their values
。 At this point, they can be defined as an object, with a few different attributes as the external state of the object, which is defined as the parameter of the object method, specified externally.
The same property is defined as an internal state, which is defined as a member of an object. Makes it possible to create only one object, which is used multiple times.

5. Enumeration (detailed in the following separately)

6, generics (detailed in the following separately)

New features of java1.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.