Sabtu, 31 Maret 2018

New Features in Java 8

New Features in Java 8

Image source: https://image.slidesharecdn.com/newfeaturesinjdk8-140227080749-phpapp02/95/new-features-in-jdk-8-7-638.jpg?cb=1393489444

Java 8 or JDK 1.8 is the most significant expansion of the Java language yet. Java 8s new features such as Lambda Expressions, Stream APIs, Nashorn, Compact Profiles, new Time APIs increase the expressive power of the platform and make it easier for developers to take advantage of modern, multicore processors. This article gives an overview of the new features in Java 8 with links to in-depth tutorials for the most important of them.
1. Lambda Expressions enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as Functional Interfaces) more compactly.
2. Method references provide easy-to-read lambda expressions for methods that already have a name. Constructor References are the equivalent forms of representation for constructors.
3. Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
4. With default methods in Java 8, multiple inheritance of behavior is now possible in Java, and it is important to understand the conflict resolution rules which resolve Diamond Problem and other conflict scenarios.
Java 8s new package java.util.function provides many useful functional interfaces for the most common scenarios. The 4 most important functional interface among them are Predicate, Consumer, Function and Supplier.
Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.
1. New java.util.stream package provides a new Streams API
to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API.
2. Java 8s new Collector interface and its multiple predefined implementations provide an efficient way to terminate the Stream operations and collect the result in a collection.
3. A new Date-Time package java.time with a new comprehensive set of date and time utilities.
4. Java 8s new enhanced methods in Collections API are covered in a series of 4 tutorials Iterable.forEach() & Iterator.remove(), Collection.removeIf(), List.sort() & List.replaceAll(), and new multi-value map methods.
5. Java 8 has introduced new internal iterators based on declarative functional programming style.
6. Comparator interface has undergone a major upgrade in Java 8 with new methods leveraging Java 8s functional programming features, comparator chaining, in-built null handling, and many more such features. Java 8 Comparator tutorial covers these new features in depth.
7. Nashorn Javascript Engine enhanced to provide a version of javascript which would run within the JVM
8. Standard Encoding and Decoding Base64,Parallel Array Sorting and Unsigned Arithematic Support.
9. JDBC 4.2 with new features and notably the JDBC-ODBC bridge has been removed.
10. Concurrency related important changes which include
o Changes to ConcurrentHashMap to support aggregate operations based on the newly added streams facility and lambda expression.
o Addition of classes to the java.util.concurrent.atomic package to support scalable updatable variables.
o Support for a common pool in ForkJoinPool.
o New StampedLock class to to provide a capability-based lock with three modes for controlling read/write access
11. Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.
12. Improved Type Inference and Method Parameter Reflection.
13. Compact Profiles contain predefined subsets of the Java SE platform and enable applications that do not require the entire Platform to be deployed and run on small devices.
14. Improved internationalization including support for Unicode 6.2.0, new Calendar and Locale APIs, Adoption of Unicode CLDR Data and the java.locale.providers System Property and Ability to Install a Custom Resource Bundle as an Extension.
15. In case you are interesting in knowing about the best books on Java 8 then you can read the.

The Complete Java 8 Comparator
Java 8s Comparator is a Functional Interface
Owing to the fact that the Comparator interface has just one abstract method, compare(), it automatically qualifies to be a Functional Interface
in Java 8. Nevertheless, Java 8 designers have gone ahead and annotated the Comparator class interface @FunctionalInterface to enforce its role as a Functional Interface. Being a functional interface, Comparator can now be used as an assignment target for a lambda expression or a method reference.
Java 8 Comparators null handling using nullsFirst()and nullsLast() methods
There are instances where the sort key value is nullable. We have to then decide whether we want to place objects with sort key as null earlier in the ordering than the objects with non-null sort key or at the end of the list after the objects with non-null sort key. Java 8 Comparators provide nullsFirst() and nullsLast() static methods for exactly such sort order handling of null valued sort keys. These methods have the signature
static Comparator nullsFirst(Comparator<? super T> comparator)
AND
static Comparator nullsLast(Comparator<? super T> comparator)
To understand the functioning of these methods, let us make the two of the employee names as null. The below two sections of code and respective output shows how the use of nullsFirst() and nullsLast() handles sorting when some objects have sort-key as null.

The Difference between APA and MLA Format

Image source: https://www.ashford.edu/sites/default/files/uploads/2014/07/Screen-Shot-2014-08-11-at-4.15.22-PM.png The two most popular form...