Java 8 launched today and it’s a groundbreaking release since Java 1.2. Although Java 5 brings big features but Java 8, as a whole, is really an enormous step for the Java language and platform.
Java 8 is the first truly revolutionary release we’ve done in a very long time
- Mark Reinhold (chief architect of the Java Platform)
Formal support of Lambda expressions, the Stream API and Functional Interfaces are spectacular improvements to java platform that allows developers to take advantage of multicore processors. Other than that new Date Time API, new JavaScript Engine, Compact Profiling, annotations and concurrency enhancements are impressive improvements.
Language and Platform Features
Lambda Expressions
Aka closures, enable developers to encapsulate a single unit of behavior and pass it to other code. Its like syntactic sugar for an anonymous class (with one method whose type is inferred) and is an object-less method or anonymous method. Its the most dominant feature of Java 8 and will have great implications for simplifying development. Behind the seen it is not an anonymous class; it actually uses invokedynamic in the byte-code.
Stream & Bulk Data Operations
Represents a sequence of objects, somewhat like the Iterator. However, unlike the Iterator, it supports parallel execution. Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.
Functional Interface
Its defined as an interface with exactly one (non default) method. This concept also applicable to interfaces that were created with earlier Java version. Java 8 comes with several functional interfaces in package,java.util.function.
Method Reference
As its title are reference to some method. Java 8 allow developers to refer any existing method or anonymous method (Lambda) as well. Method references can point to static methods, instance methods, particular object/instance methods and constructors.
Default Method
Aka Defender Methods or Virtual Extension methods, now adds support for multiple inheritance in java(multiple inheritance of implementation more precisely). It help API authors to add new methods to an interface without breaking the old code that already using the actual interface.
Type Annotations
(Annotations on Types) extends the set of annotatable locations, now developers are allowed to use annotations along with the use of a type. This new ability is primarily aimed at supporting type-checking frameworks that refine Java’s built-in type system.
Repeating Annotations
These provide the ability to apply the same annotation type more than once to the same declaration or type use. Improve the readability of source code which logically applies multiple instances of the same annotation type to a given program element.
Generalized Target-Type Inference
It expands the scope of method type-inference to support (1) inference in method context and (2) inference in chained calls. Now developers need not to manually specify type-parameters on chained callas, method call in some expressions.
Method parameter reflection
provide a mechanism to easily and reliably retrieve the parameter names of methods and constructors at runtime via core reflection. It allow to improve IDE capabilities by making parameter names more widely available.
New Date/Time API
is thread-safe, easier to read, and more comprehensive than the previous API. It will make developers more productive, whether they are using the global date and time standards or one of the regional calendars.
Base64
encoding/decoding provides a standard built-in API for encoding/decoding resources. URL Base64 Encoder provides an encoding that is URL and Filename safe.
Compact Profiles & Small VM
allow developers to use just a customized subset of the platform, and is a major step toward the merging of Java SE and Java ME. It opens horizons to work on the smallest embedded Internet of Things (IoT) devices to enterprise servers in the cloud. Small VM feature support the creation of a small VM that is no larger than 3MB.
Nashorn
replaces Rhino as the default JavaScript engine and intend to provide a version of JavaScript that would run as part of JVM. The new script engine allow to import packages, use and even extend Java classes inside JavaScript, and invoke JavaScript functions directly from Java as well.
PermGen
removed from the Hotspot JVM. Class meta-data in native memory and move interned Strings and class statics to the Java heap. The code for the permanent generation in the Hotspot JVM will be removed.
JavaFX 8
is now available for ARM platforms. JavaFX is now integrated in Java SE, developers can use the java command-line launches JavaFX applications. It also allow developers to embed Swing content into JavaFX applications.
Miscellaneous
There are many other new concepts and improvements in the platform like Concurrency API improvements, preparation for modularization (Jigsaw), Statically-Linked JNI Libraries, Parallel Array Sorting, Internationalization improvements, JDBC-ODBC Bridge removal, addition of new tools, enhancements in some existing tools and many more.
Backports
for some of these exciting features are available in market. If due to some reason application can’t immediately be upgraded to Java 8, developers can still spice their code with these exciting features to previous versions of Java. For each of the following features, here is the backport or similar library:
- Lambdas – Retrolambda
- Lazily Evaluated Sequences – totallylazy
- Optional – guava
- Date/Time – ThreeTen
- Nashorn – nashorn-backport
Source : http://zishanbilal.com/
Không có nhận xét nào:
Đăng nhận xét