1. Enhanced 'for' loop .
-Java 5 added a new style of “for” loop (sometimes called "for-in" loops)
– This code loops through each entry in an array or collection object returning one value at a time for processing -- an Iterator is used without an Iterator being defined! 2. Generics We use ‘ArrayList’ ,as example .
Now with this new feature you don't need so much force convert. 3. Enum to associated .You can see many in JDK source 1.5. 4. AutoBoxing Java 5 (Java 1.5) and later automatically “box”and ”unbox” values. – The advent of automatic Boxing and automatic Unboxing greatly simplifies code when using – Boxing and Unboxing is also important since Primitive data and Reference Type data are stored in different places; primitives representing local variables are stored on the stack while objects are stored in heap memory. Example:
5. Variable Argument Lists
New variable argument lists (VarArgs) allow specification of a method that can accept a final parameter of the same type with the number of values to be determined at runtime. Below are some rules related to this. - Only one variable argument list is allowed per method – Variable list must be the last argument defined for the method – The ellipsis "…" is used to indicate that an argument might appear a variable number of times Example:
6. Changeable return value
Before JDK5.0,you can’t change the return value.Now with this new feature You can do it here is an example.
7. Static Imports
Java 5 (Java 1.5) allows import of static items when methods or variables are used repeatedl but JDK 1.4 doesn’t support。
8.Metadata Annotations
Java 5 introduced a method for adding metadata to package and type declarations, methods, 9. Scanner Input
JDK 5.0 does’t have Scanner class,you need use JOptionPane.showInputDialog class。
| ||||||||||||||||||||||||||||||||||||
10. StringBuilder.class | ||||||||||||||||||||||||||||||||||||
|