Difference between revisions of "Changes in Java 10 and 11"

From p0f
Jump to: navigation, search
(Added assumptions.)
(ZGC (v11): added v14 news)
 
(3 intermediate revisions by the same user not shown)
Line 14: Line 14:
  
 
* fluent in the Java language (according to v8 language specification)
 
* fluent in the Java language (according to v8 language specification)
* know how Java garbage collectors work and why we need them
+
* aware of how Java garbage collectors work and why we need them
 +
* familiar with what software profiling and auditing are and how they work
 
* have a clue about Linux scripting
 
* have a clue about Linux scripting
  
Line 20: Line 21:
  
 
== Type Inference for Local Variables (v10) ==
 
== Type Inference for Local Variables (v10) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/286
  
 
Among the biggest additions to Java 10 is its [https://openjdk.java.net/jeps/286 ability to figure out the type of a variable] that has an initialiser, that is to say, perform LHS (left-hand-side) type inference.
 
Among the biggest additions to Java 10 is its [https://openjdk.java.net/jeps/286 ability to figure out the type of a variable] that has an initialiser, that is to say, perform LHS (left-hand-side) type inference.
Line 26: Line 29:
  
 
  MockEventHandler eh = new MockEventHandler();
 
  MockEventHandler eh = new MockEventHandler();
  eh.setOnSomeEvent(event -> new EventProcessor().process(event));
+
  eh.setOnSomeEvent('''event -> new EventProcessor().process(event)''');
 +
 
 +
Actually, the above expression can be simplified even further:
 +
 
 +
MockEventHandler eh = new MockEventHandler();
 +
eh.setOnSomeEvent('''EventProcessor::process''');
  
 
Notice how parameters in lambda expressions lack type declarations. Infact, they completely lack ''any'' declarations! You can [[Java 8 Lambda Expressions|read more about this in a small write-up of mine]].
 
Notice how parameters in lambda expressions lack type declarations. Infact, they completely lack ''any'' declarations! You can [[Java 8 Lambda Expressions|read more about this in a small write-up of mine]].
Line 32: Line 40:
 
In Java 10, this inference is extended even further. For cases when the compiler can infer the type of a variable, its declaration can be simplified to just the newly introduced ''reserved type'' <code>var</code>:
 
In Java 10, this inference is extended even further. For cases when the compiler can infer the type of a variable, its declaration can be simplified to just the newly introduced ''reserved type'' <code>var</code>:
  
  var x = new Integer(5);
+
  '''var''' x = new Integer(5);
  var y = MyClass.Factory.getInstance();
+
  '''var''' y = MyClass.Factory.getInstance();
 
   
 
   
 
  if (x instanceof Integer) {
 
  if (x instanceof Integer) {
Line 54: Line 62:
  
 
== Local Variable Syntax for Lambda Parameters (v11) ==
 
== Local Variable Syntax for Lambda Parameters (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/323
  
 
BLABLA
 
BLABLA
  
 
== New Nest-Based Field/Method Access Control (v11) ==
 
== New Nest-Based Field/Method Access Control (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/181
  
 
BLABLA
 
BLABLA
  
 
 
 
  
 
= Virtual Machine =
 
= Virtual Machine =
  
 
== Application Class Data Sharing (v10) ==
 
== Application Class Data Sharing (v10) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/310
  
 
BLABLA
 
BLABLA
  
 
== No-Op Garbage Collector (v11) ==
 
== No-Op Garbage Collector (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/318
  
 
BLABLA
 
BLABLA
  
 
== ZGC (v11) ==
 
== ZGC (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/333
 +
 +
Lifecycle phases:
 +
 +
* v11: experimental (Linux-only)
 +
* v14: experimental ports for macOS and Windows
 +
* v15: GA
  
 
BLABLA
 
BLABLA
 
 
  
 
= Tools =
 
= Tools =
  
 
== Flight Recorder (v11) ==
 
== Flight Recorder (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/328
  
 
BLABLA
 
BLABLA
  
 
== Low-Impact Heap Profiling (v11) ==
 
== Low-Impact Heap Profiling (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/331
  
 
BLABLA
 
BLABLA
  
 
== Launching Single-File Programs from Source (v11) ==
 
== Launching Single-File Programs from Source (v11) ==
 +
 +
* JEP: https://openjdk.java.net/jeps/330
  
 
BLABLA
 
BLABLA

Latest revision as of 11:15, 18 January 2021

Introduction

JDK 11 was released almost two months ago (as of this writing), yet it almost seems as if nobody noticed it.

After the roar and thunder of Java 9's JPMS (or Jigsaw, as some may know it) it's gone awfully quiet on the Java front.

But that's far from saying nothing is happening - after Java Module System (which was about the single biggest feature in Java 9), the world moves on.

If version 9 was mostly a clean-up release with the much-hated Java Plugin and the Applet API having been deprecated, CMS GC and all garbage collector combinations involving it, as well, several rather big improvements and additions had been made to both the language and the virtual machine in the two subsequent versions, Java 10 and Java 11.

What I assume

I assume that you are:

  • fluent in the Java language (according to v8 language specification)
  • aware of how Java garbage collectors work and why we need them
  • familiar with what software profiling and auditing are and how they work
  • have a clue about Linux scripting

Language

Type Inference for Local Variables (v10)

Among the biggest additions to Java 10 is its ability to figure out the type of a variable that has an initialiser, that is to say, perform LHS (left-hand-side) type inference.

RHS type inference should be quite familiar by now as it was by far the biggest change in Java 8 - Lambda Expressions for the Java Language allow a programmer to save space, time, and improve readability, making heavy use of type inference all the time:

MockEventHandler eh = new MockEventHandler();
eh.setOnSomeEvent(event -> new EventProcessor().process(event));

Actually, the above expression can be simplified even further:

MockEventHandler eh = new MockEventHandler();
eh.setOnSomeEvent(EventProcessor::process);

Notice how parameters in lambda expressions lack type declarations. Infact, they completely lack any declarations! You can read more about this in a small write-up of mine.

In Java 10, this inference is extended even further. For cases when the compiler can infer the type of a variable, its declaration can be simplified to just the newly introduced reserved type var:

var x = new Integer(5);
var y = MyClass.Factory.getInstance();

if (x instanceof Integer) {
    // matches
}
if (y instanceof MyClass) {
    // matches
}

There are obviously some limitations for this new expression, such as:

  • declarations without initialisers (which would require some distant action to infer the type, and that could violate the strongly-typed nature of the language because of multiple possible different initialisers at different execution points),
  • null assignments (note that null is a type, but it is fairly useless in and of its own),
  • capture variables (which need to be final, so they can not be inferred),
  • intersection types (which can not be reliably inferred),

or generally whenever an assignment type is not denotable (such as with inline arrays, method references, and even c.getClass()).

I may write more about those limitations when I've used LHS type inference more, until then feel free to have a look at the JEP defining Java type inference and its many references.

Local Variable Syntax for Lambda Parameters (v11)

BLABLA

New Nest-Based Field/Method Access Control (v11)

BLABLA


Virtual Machine

Application Class Data Sharing (v10)

BLABLA

No-Op Garbage Collector (v11)

BLABLA

ZGC (v11)

Lifecycle phases:

  • v11: experimental (Linux-only)
  • v14: experimental ports for macOS and Windows
  • v15: GA

BLABLA

Tools

Flight Recorder (v11)

BLABLA

Low-Impact Heap Profiling (v11)

BLABLA

Launching Single-File Programs from Source (v11)

BLABLA