New features in Java 5, 6, 7

Source: Internet
Author: User
Tags java se

JDK5 new features (compared to 1.4) "Turn"

1 cycles

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 type

Take ArrayList as an example, including creating a container object and getting the object inside the container:

1.5 arraylist<type> ArrayList =new arraylist<type> (); Arraylist.get (i)

1.4 ArrayList ArrayList =new ArrayList (); (Type) Arraylist.get (i)

3 Automatic packing and unpacking

Before JDK5.0, the conversion between the original type and the corresponding wrapper class could not be done automatically. To complete this conversion, you need to manually invoke the wrapper class's constructor, which can be converted automatically in the JDK5.0 environment:

1.5 Integer wrapper = n; int n = wrapper;

1.4 Integer wrapper = new integer (n); int n = wrapper.intvalue ();

4 variable return type

Before JDK5.0, when overriding a parent class method, the return type cannot be changed. Now there are new rules for overriding methods. As follows, 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 feature is not supported for previous versions of 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

The previous version of JDK 5.0 has no scanner class and can only be replaced with the Joptionpane.showinputdialog class.

1.5 Scanner in = new Scanner (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 output

JDK5.0 Previous versions do not have a printf method and can only be replaced with 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 Agent

In previous versions of JDK5.0, classes such as Jframe,jdialog,japplet did not have the 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, which does not have synchronization, which makes the analogy StringBuffer class more efficient.

New features of JDK6 (RPM)

1 Systemtray Class

In JDK6, AWT has added two new classes: Desktop and Systemtray, which can be used to open the system default browser to browse the specified URL, open the system default mail client to send mail to the specified mailbox, open or edit the file with the default application (for example, Using Notepad to open a file with the txt suffix, print the document with the system's default printer, which can be used to create a tray program in the system Tray area.

2 using JAXB2 to implement mappings between objects and XML

JAXB is the abbreviation for the Java Architecture for XML binding that transforms a Java object into an XML format and vice versa.

3 new Stax

StAX (the streaming API for XML) is an API that handles XML documents in addition to DOM and sax in JDK6.0

4 new Compiler API

You can use JDK6 's compiler API to dynamically compile Java source files. This feature is useful for applications that are dynamically compiled, such as JSP Web server, when we manually modify the JSP, we do not want to restart the WEB server to see the effect, then we can use the compiler API to dynamically compile the JSP file

5 Lightweight HTTP Server

JDK6 provides a simple HTTP Server API, and the programmer must implement the HttpHandler interface on its own, Httpserver calls the HttpHandler implementation class's callback method to handle the client request.

6 plug-in annotation processing API (pluggable Annotation processing API)

The plug-in annotation processing API provides a set of standard APIs to handle annotations, which puts method, package, constructor, type, variable, enum, Java language elements such as annotation are mapped to types and elements to map the semantics of the Java language into objects.

7 Developing console programs with console

The Java.io.Console class is available in JDK6 to access character-based console devices.

8 Web Service metadata (Web services metadata)

9 simpler, more powerful JAX-ws

The abbreviation for the Java Architecture for XML Web Services is a framework for developing WEB services applications in Java and XML.

10 scripting language Support (Scripting)

JDK6 adds support for scripting languages by compiling the scripting language into bytecode, which also allows the scripting language to enjoy many of the advantages of the Java platform, including portability, security, and so on, because it is now compiled into bytecode and then executed, So the efficiency is much higher than the original interpretation side.

One-jtable sorting and filtering

The original jtable is basically only display data, in JDK6 added to the jtable sorting and filtering function

========================================================

7.0 Features

Oracle has two products that implement the Java Platform Standard Edition (Java SE) 7:java se Development Kit (JDK), 7 and Java SE operating Environment (JRE) 7.

A superset of JRE 7 in JDK 7 and everything in JRE 7, along with tools such as the compilers and debuggers necessary to develop applets and applications. JRE7 provides class libraries, Java Virtual machines (JVMs), and other components required to run applets and applications written using the Java programming language.


The following conceptual diagram illustrates the Java component technology:

The "new" document

The documentation is updated regularly to provide insight into the development of new features on the Java platform. Some of the most recent updates include:

1.Swing

The following topics are included:

New components in the Jlayerclass swing package to support custom drawing

Nimbuslook & Feel Swing package with the latest U components to support custom skins

Heavyweightand lightweight components in the latest properties in the swing package to enable transparent and translucent forms

Shapedand Translucent the latest components in the Windows swing package to implement a custom shape form


Hue-saturation-luminance (HSL) color selectionin jcolorchooser Class color selector to support color saturation and brightness

Image 1NimbusLook & Feel

Image 2TranslucentWindow

Image 3GradientWindow

Image 4ShapedWindow

Image 6 internalframemixingfixed

2. Network Enhancements for Java SE 7

The Urlclassloader.close method has been added. This approach effectively eliminates the problem of how to support the implementation of classes and resource updates that are loaded from a particular code base, especially in jar files. For more information, see Fit to URLClassLoader.

Socket Direct Protocol (SDP) provides access to high-performance network connections; In the Java tutorial, see Understanding Socket direct protocols.

3. Javase 7 Enhancements in the collections framework

has joined the Transferqueue interface, which is a complete blockingqueue interface. The LinkedTransferQueue class implements the Transferqueue interface.

4. Client JRE Performance – Quick reference

Java's Rich Internet Application (RIA) technology is maturing. New features in each Java Runtime Environment (JRE) software version are added. This quick reference helps you keep up with the vibrant technology and implementation of the elegant RIA solution that works in all versions of the client JRE software. The Quick reference provides information about the important features added at the beginning of each version of the JRE software with the release of Java SE 6 Update 10.

Widgets that are dragged by a window can be decorated with a default or custom caption, and you see a request and a custom draggable applet. The following enhancements have been made to the syntax of the JNLP file; JNLP file Syntax: (1) OS elements can now contain specific versions of Windows, such as Windows Vista or Windows 7, in information and resource properties. (2) The application can use the install properties in the shortcut element to specify the desire to install them. The Javaweb start cache for installed applications is removed when cleared, but can be explicitly removed using the Java Control Panel. (3) The Java Web Start application can be deployed without specifying the CODEBASE property; a no code base deployment JNLP file can be embedded in an HTML page; The applet tag is embedded in the JNLP file.

You can check the status variable of the applet while it loads to determine whether the applet is ready to process the request from the JavaScript code, and handle the initialization state with the event handler.

You are now in control of the window's decoration style and start with a shortcut to the title of an applet, or a drag-and-drop browser; see request and customize to develop a draggable applet for the decoration of applets.

5. Java XML Technology Enhancements

Javaapi included in this release for XML processing (JAXP) 1.4.5 support?? Java 2.2.3 Architecture for XML binding (JAXB), and supports XML Web service (JAX-WS) 2.2.4 for Java APIs.

6. Java.lang Bag

Potential deadlock multi-threading, non-layered delegate custom ClassLoader is eliminated; see multithreading in the Java SE 7 custom ClassLoader.

7.Java Virtual Machine

Java Virtual machine support for non-Java languages a new JVM directive was introduced in Java SE7, which simplifies the implementation of dynamic type programming languages on the JVM.

The garbage collector is a server-style garbage collector that supersedes the concurrency Token-purge collection (CMS).

Java hotspot Virtual Machine performance enhancements

8. Java I/O

The Java.nio.file package and its associated packages, Java.nio.file.attribute, provide file I/O and full support for accessing the file system; see the file I/O (featured Nio.2). The representative of NIO is non-blocking I/O. (1) Catalogue <java home>/samples/Nio/chatserver/contains a sample demo Java.nio.file package contains a new API. (2) directory <java home>/demo/NIO/ZIPFS/Example Demonstration of NFS (Network File system) file system with Nio.2.

9. Security

9.1 A new local vendor has been added to provide several ECC-based algorithms (ECDSA/ECDH); see the Pkcs#11 Reference Guide for the support algorithms provided by Sun Pkcs#11 in Java.

The 9.2 weak encryption algorithm can now be disabled, see Appendix D: PKI Java Programmer's Guide for disabling cryptographic algorithms and disabling cryptographic algorithms (Disabled cryptographic Algorithms) in the Java Secure Sockets extension (JSSE) Reference Guide. Related to SSL/TLS

9.3 Various enhancements have been added to the Java Secure Sockets extension.

10. Concurrency

Fork/join framework, which is based on an implementation of the Forkjoinpool class, executor interface. It is designed to efficiently run a large number of tasks using a pool of work threads. A "work-stealing technology" is used to keep all working threads busy and take full advantage of multiple processors. View the Fork/join Java tutorials. Catalogue <java home>/Sample/Forkjoin/contains sample, demo Fork/join frame.

The Threadlocalrandom class does not need to use a pseudo-random number for contention between threads, see concurrent random numbers.

The Phaser class is a new synchronization barrier, similar to the cyclicbarrier.

One. Java 2D

The new Xrender-java 2D rendering pipeline, supports modern X11-based desktops, provides graphics performance, and sees Java 2D technology Xrender flags in System properties.

Now the JDK enumerates and displays methods, such as Graphicsenvironment.getavailablefontfamilynames installed OPENTYPE/CFF fonts, which can also be identified by the Font.createfont method. See Select Font index.

The TextLayout class supports Tibetan.

Libfontconfig, font configuration API, used to select fonts, use some of the Linux implemented logical fonts; see Fontconfig Index.

12. Internationalization

Unicode 6.0.0 is supported, see Unicode for Java tutorials. Directory <java home>/demo/jfc/font2dtest/contains examples of support for demonstrating Java's Unicode 6.0.

Java SE 7 can accommodate its ISO4217 code to determine the new currency, as described in the currency class.

Java programming language

The following enhancements have been added to the Java language:

1. Binary type.

2. Use underscores in the numeric class.

3. Use the string in the switch statement.

4. Type inference for generic instance creation.

5. Compiler warnings and errors are implemented when non-materialized types of generics are used with mutable methods.

6. Try-with-resources exception handling.

6. Captures multiple exception types and re-throws improved detection exceptions.

JDBC 4.1

JDBC4.1 introduces the following features:

Added the ability to automatically turn off Connection,resultset,andstatement type resources using a try-with-resources statement. See the Closingconnections index under PROCESSINGSQL statements.

Rowset 1.1: The introduction of the Rowsetfactory interface and the Rowsetprovider class, which allows you to create all types of row sets through the JDBC driver. See the Using Therowsetfactory Interface in Usingjdbcrowset objects.

New features in Java 5, 6, 7

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.