Java 1.7 1.8 new features

Source: Internet
Author: User
Tags google guava

There are several enhancements to the new features of JDK1.7:
The 1.JDK7 syntax
1.1 The representation of a binary variable, which supports the representation of an integer type in binary, starting with 0b.
1.2 Switch statement supports string type
1.3 Try-with-resource Statements
Note: Resources that implement the Java.lang.AutoCloseable interface can be placed in a try, similar to closed resources in final, and closed in reverse order of declarations; The exception thrown by the try block is obtained by throwable.getsuppressed
1.4 Catch Multiple Exception Description: The catch exception type is final, the build bytecode is smaller than multiple catch, and the exception type is persisted rethrow
1.5 numeric-type underscores represent a more friendly representation, but be aware of some of the criteria added by underscores
1.6 The creation of a generic instance can be simplified by type inference to simplify the generic type that can be removed from the next new section, only with <>.
1.7 Passing non-materialized parameters in a variable-parameter method, improving compilation warnings and errors
1.8 More informative backtracking is the information of the exception stack when the try statement in the above try and the inside statement throw an exception at the same time
2. Some new features of NIO2
1.java.nio.file and Java.nio.file.attribute Packages support more detailed properties, such as permissions, owner
2. Symbolic and hard links support
3. Path Access file system, files support various file operations
4. Efficient access to metadata information
5. Recursive find file tree, file extension search
6. File System Modification Notification mechanism
7.File Class Operation API compatible
8. File random access Enhanced mapping a REGION,LOCL a region, absolute position read
9. AIO Reactor (Event-based) and Proactor
2.1IO and New IO Monitor file system Change notification
Get the Watchservice by Filesystems.getdefault (). Newwatchservice () and then register the path directory that you want to listen to in this watchservice, and for the file modification of this directory, add the The removal of such practices can be configured and then automatically be able to monitor the event of the response.
2.2 io and New io traverse the file tree by inheriting the Simplefilevisitor class, implementing an event traversal of the directory tree, and then through Files.walkfiletree (Listdir, opts, Integer.max_value, walk); This API to traverse the directory tree
2.3 Aio Asynchronous IO file and network asynchronous IO in Java
NIO2 implementation, are implemented with Asynchronousfilechannel,asynchronoussocketchanne, such as synchronous blocking IO, synchronous non-blocking IO, asynchronous blocking IO and asynchronous non-blocking IO. Asynchronous non-blocking IO of the operating system is implemented in Java NIO2.
3. JDBC 4.1
3.1. You can use Try-with-resources to automatically turn off connection, ResultSet, and statement resource objects
3.2. RowSet 1.1: Introducing Rowsetfactory Interfaces and Rowsetprovider classes, you can create various row driver supported by the JDBC sets, where the RowSet implementation is actually the operation of converting some operations on the SQL statement into methods, Encapsulates a number of features.
3.3. Jdbc-odbc drivers are removed in JDK8
4. Concurrency Tool Enhancements
4.1.fork-join
The biggest enhancement, take full advantage of multicore characteristics, the large problem decomposition into sub-problems, by multiple CPUs can simultaneously solve multiple sub-problems, finally merge the results, inherit recursivetask, implement the Compute method, then call the fork calculation, and finally merge the results with join.
4.2.ThreadLocalRandon concurrent random number generation class, to ensure that the concurrent random number generation of thread safety, is actually using threadlocal
4.3. Phaser similar to Cyclebarrier and Countdownlatch, but can dynamically add resources to reduce resources
5. Networking Enhancement

New URLClassLoader Close method to close resources in a timely manner, subsequent reloading of class files will not result in resource occupancy or problems being released
Urlclassloader.newinstance (New url[]{}). Close ();
New Sockets Direct Protocol
Bypassing the operating system's data copy, transferring data from one machine's memory data to another machine's memory directly over the network
6. Multithreaded Custom Class Loaders
Solve the deadlock problem that can result from loading class in concurrency, this is a new version of jdk1.6 solved, JDK7 also made some optimizations. Be interested to learn more about the official documents carefully

New features of JDK1.8
First, the default method of the interface
Java 8 allows us to add a non-abstract method implementation to the interface, just using the default keyword, which is also called the extension method.
Second, LAMBDA expression
In Java 8 You don't have to use this traditional way of anonymous objects, Java 8 provides a cleaner syntax, lambda expressions:
Collections.sort (names, (string A, string B), {

Return B.compareto (a);

});
Third, function-type interface
How does a lambda expression be represented in the Java type System? Each lambda expression corresponds to a type, usually an interface type. The "Functional interface" refers to an interface that contains only an abstract method, and each lambda expression of that type is matched to this abstract method. Because the default method is not an abstract method, you can also add a default method to your functional interface.
Iv. methods and constructor references
Java 8 allows you to use the: keyword to pass a method or a constructor reference, the code above shows how to reference a static method, and we can also refer to an object's method:
converter = Something::startswith;

String converted = Converter.convert ("Java");

System.out.println (converted);
V. LAMBDA scope
It is similar to accessing the outer scope and older versions of anonymous objects in a lambda expression. You can directly access the outer local variables labeled final, or the fields of the instance and the static variables.
Vi. Accessing local variables
You can access the outer local variables directly in the lambda expression:
Vii. accessing object fields vs. static variables
Unlike local variables, lambda internal is both readable and writable for instance fields and static variables. This behavior is consistent with the anonymous object:
Viii. default methods for accessing interfaces
The JDK 1.8 API contains a number of built-in functional interfaces, such as the comparator or runnable interfaces used in old Java, which add @functionalinterface annotations so that they can be used on lambda.
The Java 8 API also offers a lot of new functional interfaces to make things easier, some of which are from the Google Guava Library, and even if you're familiar with them, it's important to see how these are extended to lambda use.

Java 1.7 1.8 new features

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.