Java 11 Enhancements
Java 10 Enhancements
- var keyword
Java 9 Enhancements
- Java Module System
Java 8 Enhancements
- Lambda expressions
- Annotation on Java Types
Java 7 Enhancements
- Strings in switch Statement
- Java diamond operator <>:
Map<String, Integer> params = new HashMap<>(); - Simplified varargs method declaration
- Binary Literals:
byte aByte = (byte)0b00100001; - Underscores in Numeric Literals:
long creditCardNumber = 1234_5678_9012_3456L; - The try-with-resources Statement:
try (PrintWriter writer = new PrintWriter(new File("test.txt"))) { writer.println("Hello World"); } - Catching multiple exception types and rethrowing exceptions with improved type checking
- Generics
- Annotations
- Autoboxing and Unboxing
- Enumerations
- Varargs:
void foo(String... arg) - Enhanced foreach loop
int[] list = {10, 20, 30, 40}; for(int i : list) { ... } - Static Import Declarations
- assert keyword
- strictfp keyword
- Inner classes
- Reflection
initial release
Java 10
- Using type inference by declaring
var x = "";in Java 10
Java 9
- Declaring modules
- Concise try-with-resources [2]
- Anonymous diamond [2]
- Private interface methods [2]
Java 8
- Default method implementations in interfaces
- Calling default interface method implementation from implementing class:
@Override public void foo() { FooInterface.super.foo(); } staticmethods in interfaces- Declaring a method accepting a lambda-expression
- Calling a method accepting a lambda-expression
- Annotating a type with an annotation, e.g.
List<@Nonnull String> - Method references, e.g.
Object::toStringor""::toString - Repeating annotations
Java 7
switchon Strings- try-with-resources
- Diamond operator for generics:
List<String> l = new ArrayList<>(); - Declaring an
intusing a binary literal - Using underscores in
intliterals, e.g.0b0111_1111_1111_1111_1111_1111_1111_1111 - Multi-catch (
try { ... } catch (IOException | RuntimeException e) { ... })
Java 6
- Strings containing Unicode characters
- Using
αρετηas a method name - Using
αρετηas a class name - Abstract class definition
- Declaring a
short/byte/char/int/long/float/doublevariable - Declaring a method returning a
short/byte/char/int/long/float/double - Declaring a method accepting a
short/byte/char/int/long/float/double - Declaring a reference type variable (e.g.
String) - assert-Statements, e.g.
assert "" != null; breakkeyword inwhile(...) { if (...) { break; } }breakandcasekeywords inswitch-statementsswitchon enums, intscontinuekeyword inwhile(...) { if (...) { continue; } }- try-catch-finally
- do-while-loop
- while-loop
- for-loop
- foreach-loop (
for (int x : arrayOfInts) { ... }) - if-else
- Extending from a class
- Implementing an interface
- Declaring an enum
- Declaring an enum with a constructor
- Declaring a final variable
- Declaring a final method
instanceof-check- Methods declared as
native(might be difficult) - Create new instances using the
newkeyword - Visibility-modifiers (private, protected, public, no modifier)
return-statementsstaticmethodsstaticvariables- Calling a method defined in a superclass using
super.foo() synchronizedmethodssynchronizedblocks inside methods- Referencing
this - Throwing an Exception
throwsdeclarations on methods- Declaring a
transientvariable - Declaring a
volatilevariable - Initializing a variable with
null - Annotating a variable/method/class with an annotation like
@Nonnull - Applying multiple annotations to one element
- Declaring an
intusing a decimal/hex/octalliteral - Declaring an
intusing the unary operators+/-:int x = -3 - Declaring a
longusing thelorLsuffix on a number literal - Using floating point literals in decimal / scientific notation, e.g.
6.022137e+23f - Using character literals like
'a', more examples in 3.10.4 [1] - Escape sequences in strings, e.g.
"\"" - String concatenation using
+, e.g."\u005c" + "b" - Numeric operations on all kinds of types, see 4.2.2, 4.2.4 [1], including prefix/postfix operators
- Bitwise operations on
byteandint - Boolean operations, see 4.2.5 [1]
- Comparing two reference type objects with
== - Declaring arrays of primitive types as well as reference types
- Declaring multi-dimensional arrays
- Array initializers (
int[] a = { ... }andint[] a = new int[] { ... }) - Accessing array elements
- Virtual method invocations
- Static method invocations
- Generic type parameters on classes
- Generic type parameters on methods
- Upper bounds for generic type parameters, even multiple upper bounds:
<A extends Foo & Bar>, also<? extends Foo>and<? super Foo> - Using a generic class as a raw type (e.g.
List x = new ArrayList();) - Declaring an inner class
- Calling a method of the outer class from within a non-static inner class
- Declaring a static inner class
- Casting between number types
- Unchecked cast in generic method
- Automatic widening:
int x = 0; long y = x; - Autoboxing
- Declaring constructors
- Variable shadowing
- Method overloading
- Method overriding
- static imports of methods
- Declaring a named class inside a method
- Declaring an anonymous class inside a method
- Declaring a field with an initializer
- Creating a new block inside a method:
void foo() { { /* Some code here */ } } - Declaring an interface
- Declaring an annotation interface:
@interface Annotation { ... }, including a default value such asint currentRevision() default 1; - Reflection using
Foo.class,boolean.class - Declaring a static initializer:
class Foo { static { ... } } - Statement evaluation like
b = b + (b = 3); - Using parentheses to define evaluation order:
b = ((1 + 2) * 3); - Inheriting from two interfaces that both declare the same method and calling that method
- The empty statement:
; - Labeled statements
- Breaking out of an outer loop using
breakand labels - Condition operators:
x == null ? "" : x.toString();
[1] https://docs.oracle.com/javase/specs/jls/se12/jls12.pdf
[2] https://jakewharton.com/androids-java-9-10-11-and-12-support/#concise-try-with-resources