Skip to content

Instantly share code, notes, and snippets.

@linghuiluo
Last active October 8, 2021 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linghuiluo/b3d011b439f78a530320065ba160d349 to your computer and use it in GitHub Desktop.
Save linghuiluo/b3d011b439f78a530320065ba160d349 to your computer and use it in GitHub Desktop.

Back to my page

Java Version-wise Language Feature Changes

Java 11 Enhancements

Java 10 Enhancements

  • var keyword
  • Java Module System
  • 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

Java 6

Java 5

  • 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

Java 4

  • assert keyword

Java 3

Java 2

  • strictfp keyword

Java 1

  • Inner classes
  • Reflection

Java 0

initial release

All Features

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(); }
  • static methods 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::toString or ""::toString
  • Repeating annotations

Java 7

  • switch on Strings
  • try-with-resources
  • Diamond operator for generics: List<String> l = new ArrayList<>();
  • Declaring an int using a binary literal
  • Using underscores in int literals, 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/double variable
  • 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;
  • break keyword in while(...) { if (...) { break; } }
  • break and case keywords in switch-statements
  • switch on enums, ints
  • continue keyword in while(...) { 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 new keyword
  • Visibility-modifiers (private, protected, public, no modifier)
  • return-statements
  • static methods
  • static variables
  • Calling a method defined in a superclass using super.foo()
  • synchronized methods
  • synchronized blocks inside methods
  • Referencing this
  • Throwing an Exception
  • throws declarations on methods
  • Declaring a transient variable
  • Declaring a volatile variable
  • Initializing a variable with null
  • Annotating a variable/method/class with an annotation like @Nonnull
  • Applying multiple annotations to one element
  • Declaring an int using a decimal/hex/octalliteral
  • Declaring an int using the unary operators +/-: int x = -3
  • Declaring a long using the l or L suffix 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 byte and int
  • 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 = { ... } and int[] 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 as int 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 break and 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment