New Features of jdk5 (compared with 1.4]
1 Loop
For (type variable: array) {body}
For (type variable: arraylist) {body}
And 1.4 must be:
For (INT I = 0; I <array. length; I ++) {type variable = array [I]; body}
For (INT I = 0; I <arraylist. Size (); I ++) {type variable = (type) arraylist. Get (I); body}
2 generic
Take arraylist as an example, including creating a container object and obtaining the object operations in the container:
1.5 arraylist <type> arraylist = new arraylist <type> (); arraylist. Get (I)
1.4 arraylist = new arraylist (); (type) arraylist. Get (I)
3. Automatic packing and unpacking
Before jdk5.0, the conversion between the original type and the corresponding packaging class cannot be completed automatically. To complete this conversion, You need to manually call the constructor of the packaging class. In the jdk5.0 environment, you can automatically convert:
1.5 int A = 0; integer wrapper = A; int n = wrapper;
1.4 integer wrapper = new INTEGER (n); int n = wrapper. intvalue ();
4. Variable return types
Before jdk5.0, the return type cannot be changed when the parent class method is overwritten. A new rule is available to overwrite the method. A typical example is the clone () method:
1.5 Public Employee clone (){...}
...
Employee cloned = E. Clone ();
1.4 Public object clone (){...}
...
Employee cloned = (employee) E. Clone ();
5. Static Import
The static import function is not supported in versions earlier than JDK 5.0.
Import static java. Lang. Math;
Import static java. Lang. system;
...
1.5 out. println (SQRT (PI ));
1.4 system. Out. println (math. SQRT (math. Pi ));
6 console input
JDK 5.0 earlier versions do not have a category class and can only be replaced by the joptionpane. showinputdialog class.
1.5 bytes in = new bytes (system. In );
System. Out. Print (prompt );
Int n = in. nextint ();
Double X = in. nextdouble ();
String S = in. nextline ();
1.4 string input = joptionpane. showinputdialog (prompt );
Int n = integer. parseint (input );
Double X = double. parsedouble (input );
S = input;
7. format the output
The printf method is not available in versions earlier than JDK and can only be replaced by numberformat. getnumberinstance.
1.5 system. Out. printf ("% 8.2f", X );
1.4 numberformat formatter = numberformat. getnumberinstance ();
String formatted = formatter. Format (X );
For (INT I = formatted. Length (); I <8; I ++)
System. Out. Print (""); system. Out. Print (formatted );
8. Content panel proxy
In previous versions of JDK, classes such as jframe, jdialog, and japplet have no proxy add and setlayout methods.
1.5 add (component); setlayout (manager );
1.4 getcontentpane (). Add (component); getcontentpane (). setlayout (manager );
9 stringbuilder class
JDK 5.0 introduces the stringbuilder class. The method of this class is not synchronized, which makes the stringbuffer class more efficient.
New Features of JDK 6)
1 systemtray class
In JDK 6, two classes are added to AWT: desktop and systemtray. The former can be used to open the specified URL in the default browser of the system and open the default mail client to send emails to the specified mailbox, use Default ApplicationProgramOpen or edit a file (for example, open a file suffixed with TXT in Notepad), and print the file with the default printer of the system. The latter can be used to create a program in the system tray area.
2. Use jaxb2 to map objects to XML
Jaxb is short for Java architecture for XML binding. It can convert a Java object into XML format, and vice versa.
3. Added Stax.
Stax (the streaming API for XML) is another API for processing XML documents in jdk6.0 except Dom and sax.
4. Added compiler API
You can use the compiler API of JDK 6 to dynamically compile Java source files. This feature is quite useful for applications that use dynamic compilation, such as JSP web server. After we manually modify JSP, we do not want to restart the Web server to see the effect, at this time, we can use the compiler API to dynamically compile JSP files.
5 lightweight HTTP Server
JDK 6 provides a simple HTTP Server API. programmers must implement the httphandler interface by themselves. httpserver calls the callback method of the httphandler implementation class to process client requests.
6 plug-in Annotation processing API (Pluggable annotation processing API)
The plug-in Annotation processing API provides a set of standard APIs to process annotations. It maps methods, packages, constructor, type, variable, Enum, annotation, and other Java language elements to types and elements, in this way, the semantics of the Java language is mapped to an object.
7. Use the console to develop console programs
JDK 6 provides Java. Io. Console class for accessing character-based console devices.
8. Web services metadata)
9 simpler, more powerful JAX-WS
Java architecture for XML Web Services is a framework for developing web services applications using Java and XML.
10 Scripting)
Jdk6 has added support for the script language. In principle, it compiles the script language into bytecode, so that the script language can also enjoy many advantages of the Java platform, including portability and security. In addition, since the code is compiled into bytecode and then executed, the execution efficiency is much higher than that of the original side.
11 jtable sorting and filtering
The original jtable basically only displays data. The jtable sorting and filtering function is added in jdk6.