JDK11 - Java 11 - What's new features in Java 11
After Java 8, Java 11 is the latest version with Long Term Support (LTS). Oracle stops supporting Java 8 since January 2019 and for more help, you will have to pay.
Java 11 Release Date : 25 September 2018
Oracle JDK :
For commercial use Oracle JDK will no longer be free. No free long term support (LTS) will be offered by Oracle since Java 11 for any single Java version. You may use it in development stage, but to commercially use it, must purchase a license.
Better option is to pay for commercial support to Oracle and only switch from one LTS to the next. This way, you're going to get all updates and Java 11 supported up to 2026 and you can download Java 17 on 2021.
Download : JDK 11
OpenJDK :
Although Oracle JDK is no longer free, Oracle Open JDK builds can still be downloaded. You can use OpenJDK and upgrade them if necessary to remain free unless you want Enterprise-level use and ready to pay support fees
Even after support ends, you can remain on Java free version. While security updates will not be received, they may open security loopholes.
Download : openJDK 11 archivedHaving grasped the various Java JDKs, it is now possible to examine the core features for developers of Java 11. Some important JEPs are going to be understand next.
Java features :
- 181: Nest-Based Access Control
- 309: Dynamic Class-File Constants
- 315: Improve Aarch64 Intrinsics
- 318: Epsilon: A No-Op Garbage Collector
- 320: Remove the Java EE and CORBA Modules
- 321: HTTP Client (Standard)
- 323: Local-Variable Syntax for Lambda Parameters
- 324: Key Agreement with Curve25519 and Curve448
- 327: Unicode 10
- 328: Flight Recorder
- 329: ChaCha20 and Poly1305 Cryptographic Algorithms
- 330: Launch Single-File Source-Code Programs
- 331: Low-Overhead Heap Profiling
- 332: Transport Layer Security (TLS) 1.3
- 333: ZGC: A Scalable Low-Latency Garbage Collector(Experimental)
- 335: Deprecate the Nashorn JavaScript Engine
- 336: Deprecate the Pack200 Tools and API
-
181: Nest-Based Access Control
Java allows classes and interfaces to be nested within each other. These nested forms have unlimited access to each other, including private fields, methods, and constructors.
Nests allow nested classes, which are part of the same enclosing class but are compiled into different class files, to access each other's private members without the need for compilers to insert synthetic accessibility-broadening bridge methods. This is a Java class bytecode level change.
public class TestOuter { public void testingOuterPublic() { } private void testingOuterPrivate() { } class TestInner { public void testingInner() { testingOuterPrivate(); } } }
TestOuter and TestInner form a nest together, they are each other's nestmates.
The method testingOuterPrivate() can be accessed inside inner class, even tough testingOuterPrivate() method is private.If we compile above class, will get compilation error. This is because of the reason that the outer and nested classes are compiled to different files and they need package-private visibility to access each other's private members. JVM access rules do not permit private access between nestmates.
Java 11 provides JVM level support for private access through the "NestMembers" and "NestHost" attributes within outer / nested classes.
-
NestMembers
corresponds to nested classes. -
NestHost
corresponds to the enclosing outer class.
Now these attributes connect outer and nested classes, rather than package-private bridge methods created synthetically.
If we run above code in Java 10, will get below exception:package com.techgeeknext; import java.lang.reflect.Field; public class TestOuter { private static int testingNumber = 17; public static class NestedInnerTest { public static void test() throws Exception { Field value = TestOuter.class.getDeclaredField("testingNumber"); value.setInt(null, 12); } } public static void main(String[] args) throws Exception { NestedInnerTest.test(); System.out.println(TestOuter.testingNumber); } }
Whereas in Java 11, it will run successfully without exception with below output:Exception in thread "main" java.lang.IllegalAccessException: class com.techgeeknext.TestOuter$NestedInnerTest cannot access a member of class com.techgeeknext.controller.TestOuter with modifiers "private static" at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376) at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:639) at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075) at java.base/java.lang.reflect.Field.setInt(Field.java:958) at com.techgeeknext.controller.TestOuter$NestedInnerTest.test(TestOuter.java:12) at com.techgeeknext.controller.TestOuter.main(TestOuter.java:18)
12
-
-
JEP 309: Dynamic Class-File Constants
The Java class-file format is now expanding support for a new kind of constant pool, called CONSTANT_Dynamic. The loading of CONSTANT_Dynamic delegates the creation of a bootstrap method. Same as linking an invokedynamic call site delegates linkage to a bootstrap method. Same as, Java 7 which introduces MethodHandle and MethodType entry in constant pool. You can refer 4.4. The Constant Pool , to see the format of the constant pool.
-
JEP 315: Improve Aarch64 Intrinsics
Improve the current string and array intrinsic, and added new intrinsics on AArch64 processors for the java.lang.Math sin, cos and log functions. Intrinsics are used to optimize CPU architecture-specific assembly code that is executed for a given method to boost performance, instead of generic Java code. Although most of the intrinsics are already implemented in port AArch64, optimized intrinsics are still lacking for the following java.lang.Math methods:
- sin (sine trigonometric function)
- cos (cosine trigonometric function)
- log (logarithm of a number) This JEP is intended to cover this gap by implementing optimized intrinsics for these methods.
-
JEP 318: Epsilon: A No-Op Garbage Collector
Epsilon is the "No Op" garbage collector. It allocates new memory but never recycles it. Once the application exhausts the available Java heap, the JVM shuts down. It means, Epsilon will allow your application to run out of memory and crash. Elipson is good only for test environments and no-op garbage collector is useful for measuring and managing application performance.
Java 11 also added Z garbage collector (ZGC), which promises to manage large heaps with high throughput and short pause times. You need to specify below two runtime switches on the command line, to tell the JVM to use the Epsilon GC
XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
Below command generate heap dump if JVM runs out of memory.
-XX:HeapDumpOnOutOfMemoryError
Run specified command when an out-of-memory error occurs.
-XX:OnOutOfMemoryError=
-
JEP 320: Remove the Java EE and CORBA Modules
Java 11 removed the Java EE and CORBA modules from the Java SE Platform and the JDK, these modules were already deprecated in Java 9 with the declared intent to remove them in a future release.
- java.xml.ws (JAX-WS, plus the related technologies SAAJ and Web Services Metadata)
- java.xml.bind (JAXB)
- java.activation (JAF)
- java.xml.ws.annotation (Common Annotations)
- java.corba (CORBA)
- java.transaction (JTA)
- java.se.ee
- jdk.xml.ws (Tools for JAX-WS)
- jdk.xml.bind (Tools for JAXB)
-
JEP 321: HTTP Client (Standard)
It standardizes Http Client API, in the java.net.http package, based upon the incubated API, and removed the incubated API. The new API supports both HTTP/1.1 and HTTP/2. It is designed to enhance the overall performance of sending requests by a client and receiving responses from the server. It also natively supports WebSockets.
-
JEP 323: Local-Variable Syntax for Lambda Parameters
It allows var to be used when declaring the formal parameters of implicitly typed lambda expressions.
In Java 10, Local Variable Type Inference was introduced.
var str = "Java 10"; // infers String var list = new ArrayList<String>(); // infers ArrayList<String> var stream = list.stream(); // infers Stream<String>s var bos = new ByteArrayOutputStream();
Java 11, allows var to be used to declare the formal parameters of an implicitly typed lambda expression.
(var a, var b) -> a + b
The examples below are illegal:
// Not allowed to mix 'var' and 'no var' in implicitly typed lambda expression (var a, b) -> a+b // Not allowed to mix 'var' and manifest types in explicitly typed lambda expression (var a, int b) -> a+b
-
JEP 324: Key Agreement with Curve25519 and Curve448
Java makes further improvement in cryptography which provides security and performance. This feature implements a key agreement using Curve25519 and Curve448. Other cryptography libraries, such as OpenSSL and BoringSSL, already support key exchanges using Curve25519 and Curve448.
For more information, you go though Curve25519 and Curve448 for the Internet Key Exchange Protocol Version 2 (IKEv2) Key Agreement Document
-
JEP 327: Unicode 10
Java 11 has upgraded existing platform APIs to support version 10.0 of the Unicode Standard.
It supports the latest Unicode version, particularly in the classes below:
- Character and String in the java.lang package
- NumericShaper in the java.awt.font package
- Bidi, BreakIterator, and Normalizer in the java.text package
-
JEP 328: Flight Recorder
Java Flight Recorder (JFR) is a profiling tool that collects data about events during the execution of a Java application in Java Virtual Machine (JVM). JFR is integrated into the JVM and part of the JDK distribution.
- Using Command Line : Compile FlightRecTest Java program by executing the below command, which will generate FlightRecTest.class file at src/com/techgeeknext/flightrecorder location.
Once compilation is successful, the following options can be taken to start the program:javac -d out -sourcepath src/com/techgeeknext/flightrecorder/FlightRecTest.java
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=200s,filename=recording.jfr -cp ./out/ com.techgeeknext.flightrecorder.FlightRecTest
- Using Diagnostic Command: The jcmd tool also allows registration of events to start. To start a 70-second recording on the running Java process with the identifier 4532 and save it to recording.jfr in the current
directory, use the following:
Below commands relevant to Java Flight Recorder are:jcmd 4532 JFR.start duration=70s filename=recording.jfr
//Start a recording. JFR.start //It check the status of all recordings running for the specified process, including the recording file name, identification number, duration. JFR.check //It stop recording with a specific identification number, by default, recording 1 is stopped. JFR.stop //It dump the data collected by the recording with a specific identification number, by default, data from recording 1 is dumped. JFR.dump
- Using Command Line : Compile FlightRecTest Java program by executing the below command, which will generate FlightRecTest.class file at src/com/techgeeknext/flightrecorder location.
-
JEP 329: ChaCha20 and Poly1305 Cryptographic Algorithms
Java 11 has Implement the ChaCha20 and ChaCha20-Poly1305 ciphers.
ChaCha20 is a new stream cipher which replaces the older, insecure RC4 stream cipher.
Poly1305 is a cryptographic Message Authentication Code (MAC), used on both Encrypted and Decrypted messages, it creates the authentication token and guarantees the integrity of the message.In ChaCha20-Poly1305 algorithm, ChaCha20 Stream cipher performs the Encryption and Poly1305 performs the Authentication. The ChaCha20 and ChaCha20-Poly1305 algorithms will implement the javax.crypto.CipherSpi API within the SunJCE provider.
Can refer for documentation. -
JEP 330: Launch Single-File Source-Code Programs
It enhances the Java launcher to run the program provided as a single Java source code file, including the use of "shebang" files and related techniques from within the script.
-
331: Low-Overhead Heap Profiling
It provides a way to get information from the JVM about Java object heap allocations that:
- Is low-overhead enough to be enabled by default continuously
- Is accessible via a well-defined, programmatic interface
- Sample all allocations (which is not limited to allocations that are in one particular heap region or that were allocated in one particular way)
- It can be defined in an implementation-independent way (i.e., without relying on any particular GC algorithm or VM implementation)
- It provide information about both live and dead Java objects.
-
332: Transport Layer Security (TLS) 1.3
Java implemented version 1.3 of the Transport Layer Security (TLS) Protocol RFC 8446.
Transport Layer Security, or TLS, is a cryptographic protocol that protects data exchanged over a computer network. TLS (Transport Layer Security) and is the successor to SSL (Secure Sockets Layer). TLS provides secure communication between web browsers and servers.
TLS 1.3 is a major revision of the TLS protocol and provides significant security and performance improvements over previous versions.
-
333: ZGC: A Scalable Low-Latency Garbage Collector(Experimental)
Java 11 has some great feature, one is Z Garbage Collector (ZGC). The Z Garbage Collector, also known as ZGC, is a low latency scalable garbage collector designed to meet the following objectives.
- Pause times shall not exceed 10 ms
- Handle heaps ranging from a few hundred megabytes to multi terabytes in size
- Pause times do not increase with the size of the heap or live-set.
-
335: Deprecate the Nashorn JavaScript Engine
Below two JDK modules will be terminally deprecated, by using annotation @Deprecated(forRemoval=true):- jdk.scripting.nashorn -- contains the jdk.nashorn.api.scripting and jdk.nashorn.api.tree packages.
- jdk.scripting.nashorn.shell -- contains the jjs tool. Running jjs will display a warning:
-
336: Deprecate the Pack200 Tools and API
Below three types will be deprecated from java.base module, i.e. with annotation @Deprecated(forRemoval = true):- java.util.jar.Pack200
- java.util.jar.Pack200.Packer
- java.util.jar.Pack200.Unpacker
Take a look at our Suggested Posts :
Quick glance on earlier Java Versions Features :
Java 14 Features - JDK 14
Java 14 is now available!
Java 14 (Java SE 14) and its Java Development Kit 14 (JDK 14) open-source has been released on 17 March 2020, the most common coding language and application platform in the world.A significant number of Java Enhancement Proposals (JEPs) have been released in version 14. (Even more JEPs than Java 12 and 13 combined)
JAVA 14 addresses a total of 16 main enhancements/changes (JEPs) ranging from the Java language support to the latest APIs for ongoing JDK flight recorder monitoring. The entire feature list consists of:
- Pattern Matching for instanceof
- Non-Volatile Mapped Byte Buffers
- Helpful NullPointerExceptions
- Switch Expressions (Standard)
- Packaging Tool (Incubator)
- NUMA-Aware Memory Allocation for G1
- JFR Event Streaming
- Records (Preview)
- Deprecate the Solaris and SPARC Ports
- Remove the Concurrent Mark Sweep (CMS) Garbage Collector
- ZGC on macOS
- ZGC on Windows
- Deprecate the ParallelScavenge + SerialOld GC Combination
- Remove the Pack200 Tools and API
- Text Blocks (Second Preview)
- Foreign-Memory Access API
Java 13 Features - JDK 13
- Dynamic CDS Archives
- ZGC: Uncommit Unused Memory
- Reimplement the Legacy Socket API
- Switch Expressions (Preview)
- Text Blocks (Preview)
Java 12 Features
- Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
- Microbenchmark Suite
- Switch Expressions (Preview)
- JVM Constants API
- One AArch64 Port, Not Two
- Default CDS Archives
- Abortable Mixed Collections
- Promptly Return Unused Committed Memory from G1
Java 10 Features
- Local-variable type inference
- Experimental Java-based JIT compiler.This is the integration of the Graal dynamic compiler for the Linux x64 platform
- Application class-data sharing. This allows application classes to be placed in the shared archive to reduce startup and footprint for Java applications
- Time-based release versioning
- Parallel full GC
- Garbage-collector interface
- Additional Unicode language-tag extensions
- Root certificates
- Thread-local handshakes
- Heap allocation on alternative memory devices
- Remove the native-header generation tool - javah
- Consolidate the JDK forest into a single repository
Java 9 Features
- Modularization of the JDK under Project Jigsaw (Java Platform Module System)
- jshell: The Java Shell (a Java REPL)
- Ahead-of-time compilation
- XML catalogs
- More concurrency updates. It includes a Java implementation of Reactive Streams, including a new Flow class that included the interfaces previously provided by Reactive Streams
- Variable handles: define a standard means to invoke the equivalents of various java.util.concurrent.atomic and sun.misc.Unsafe operations
- jlink: The Java Linker: create a tool that can assemble and optimize a set of modules and their dependencies into a custom run-time image. It effectively allows to produce a fully usable executable including the JVM to run it
- JavaDB was removed from JDK
- HiDPI graphics: automatic scaling and sizing
Java 8 Features
- Language-level support for lambda expressions and default methods (virtual extension methods) which allow the addition of methods to interfaces without breaking existing implementations.
- Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
- Annotation on Java types
- Unsigned integer arithmetic
- Repeating annotations
- Date and time API
- Statically-linked JNI libraries
- Launch JavaFX applications (direct launching of JavaFX application JARs)
- Remove the permanent generation
Java 7 Features
- JVM support for dynamic languages
- Compressed 64-bit pointers
- Strings in switch
- Automatic resource management in try-statement
- Improved type inference for generic instance creation, aka the diamond operator <>
- Simplified varargs method declaration
- Binary integer literals
- Allowing underscores in numeric literals
- Catching multiple exception types and rethrowing exceptions with improved type checking
- Concurrency utilities
- New file I/O library adding support for multiple file systems
- Timsort is used to sort collections and arrays of objects instead of merge sort
- Library-level support for elliptic curve cryptography algorithms
- An XRender pipeline for Java 2D, which improves handling of features specific to modern GPUs
- New platform APIs for the graphics features
- Enhanced library-level support for new network protocols, including SCTP and Sockets Direct Protocol
- Upstream updates to XML and Unicode
- Java deployment rule sets
Java 6 Features
- Support for older Win9x versions dropped
- Scripting Language Support
- Dramatic performance improvements for the core platform, and Swing.
- Improved Web Service support through JAX-WS.
- JDBC 4.0 support.
- Java Compiler API
- Upgrade of JAXB to version 2.0
- Support for pluggable annotations
- Many GUI improvements, such as integration of SwingWorker in the API, table sorting and filtering, and true Swing double-buffering (eliminating the gray-area effect).
- JVM improvements include: synchronization and compiler performance optimizations, new algorithms and upgrades to existing garbage collection algorithms, and application start-up performance.
- Java 6 can be installed to Mac OS X 10.5 (Leopard) running on 64-bit (Core 2 Duo and higher) processor machines.[54] Java 6 is also supported by both 32-bit and 64-bit machines running Mac OS X 10.6
Java 5 Features
- Generic
- Metadata
- Autoboxing/unboxing
- Enumerations
- Varargs
- Enhanced for each loop
- Improved
- Static imports
- Improvements - Semantics of execution for multi-threaded Java programs
- Improvements - Automatic stub generation for RMI objects
- Improvements - Swing: New skinnable look and feel, called synth
- Improvements - The concurrency utilities in package java.util.concurrent
- Improvements - Scanner class for parsing data from various input streams and buffers