Java 5
1. for-each syntax
2. @override was introduced in Java 5, modified in Java 7
add this annotation and the compiler will produce an error message if you accidentally overload instead of overriding.
3. Variable-Length Argument Lists: a variable-length argument is specified by three periods(…). For Example,
public static void m(int ... varargs)
{
// method body
}
4. enum keyword
An especially nice feature is the way that enums can be used inside switch statements.
enum classes cannot have finalize methods. enum can't deserialize enum.
5. covariant return types
details see example.
6. add Queue.
7. add Iterable Interface.
Java 8
1. forEach() which is heavily used.
(the Java compiler produces its own “assembly code,” but this code is run by the Java Virtual Machine rather than directly on a hardware CPU).
2. With Java 8 the interface waters have been muddied a bit, because Java 8 allows both default methods and static methods.
The default keyword formerly used only in switch statements and annotations. Details see here.
3. adds the ability to include static methods inside interfaces.
4. lambda expressions
Before Java 8, the only way to produce closure-like behavior was through inner classes. With Java 8, we now have lambda expressions which also have closure behavior, but with much nicer and more concise syntax. Details see here.
5. Before Java 7(include 7), we had to, in effect, duplicate the type declaration on both sides, like this:
ArrayList<String> strings = new ArrayList<String>();
, in Java 8, we would use like this:
ArrayList<String> strings = new ArrayList<>();
details see here.
6. functional interface
to be added later ......
references:
1. http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/Enum.java
2. http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/function
3. https://howtodoinjava.com/java8/functional-interface-tutorial/