Java 15 New Features
July 08, 2021
On this page we will discuss new features and enhancements introduced in Java 15.
Contents
Record Classes (JEP 384)
Therecord
class was introduced in Java 14 as preview feature. In Java 15, the record
class is extended as preview feature. The additional feature is that now record
can be used to create a local record within a method like local classes.
package com.concretepage; record Rectangle(int length, int width) { } public class MyApp { public static void main(String[] args) { Rectangle rec = new Rectangle(12, 5); System.out.println(rec.length()); //12 System.out.println(rec.width()); //5 //local record class record Employee(String name, int age) { } Employee emp = new Employee("Mahesh", 22); System.out.println(emp.name); //Mahesh System.out.println(emp.age); //22 } }
Sealed Classes (JEP 360)
This is a preview feature in Java 15. A sealed class is a class that can be inherited by only specified classes. Look into the below code.public sealed class Animal permits Cow, Lion { }
sealed
keyword. The above sealed class Animal
can only be extended by Cow
and Lion
classes.
public class Cow implements Animal { } public class Lion implements Animal { }
Text Blocks (JEP 378)
Text block was introduced in Java 13 as preview feature. In Java 15, it has been adopted as permanent language feature. A text block is a multi-line string literal that avoids the need for most escape sequences and automatically formats the string.Using "one-dimensional" string literals.
String query = "SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE`\n" + "WHERE `CITY` = 'VARANASI'\n" + "ORDER BY `EMP_ID`, `LAST_NAME`;\n";
Using a "two-dimensional" block of text.
String query = """ SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE` WHERE `CITY` = 'VARANASI' ORDER BY `EMP_ID`, `LAST_NAME`; """;
Added CharSequence::isEmpty
(JDK-8215401)
In Java 15, the CharSequence
interface has added a default method isEmpty
as following.
default boolean isEmpty()
StringBuffer sb1 = new StringBuffer(); System.out.println(sb1.isEmpty()); //true StringBuffer sb2 = new StringBuffer("Krishna"); System.out.println(sb2.isEmpty()); //false
Hidden Classes (JEP 371)
Hidden classes are introduced in Java 15. Hidden classes are the classes that cannot be used directly by the bytecode of other classes. Hidden classes are mostly used in framework developments that generate classes at run time and use them indirectly, via reflection. TheClass::getName
traditionally returns a binary name but for hidden class, it returns a string that contains an ASCII forward slash (/).
Configure Third Port for Remote JMX (JDK-8234484)
Now we can configure third port for remote JMX (local only) as following.Third port:
com.sun.management.jmxremote.local.port=<port#>
com.sun.management.jmxremote.port=<port#> com.sun.management.jmxremote.rmi.port=<port#>
New Options Added to jhsdb
for Debug Mode (JDK-8196751)
Three new options have been added to jhsdb
for debug mode.
(1) --rmiport <port> : specify a RMI connector port number
(2) --registryport <port> : specify a RMI registry port number.
(3) --hostname <hostname> : specify a RMI connector host name.
Other New Features and Enhancements
1. JDK-8239383: In this release the Unicode support has been upgraded to 13.0.2. JDK-8243099: A new JDK-specific socket option
SO_INCOMING_NAPI_ID
has been added to jdk.net.ExtendedSocketOptions
.
3. JDK-8176894: The
TreeMap
class now provides overriding implementations of the putIfAbsent
, computeIfAbsent
, computeIfPresent
, compute
, and merge
methods.
4. JDK-8196729: A new
-r <port>
option has been added to the jstatd
command to specify the RMI connector port number. If a port number is not specified, a random available port is used.
5. JDK-8237354: A new integer option gz has been added to the
GC.heap_dump
diagnostic command. If it is specified, it will enable the gzip compression of the written heap dump.
6. JDK-8222383: The Oracle JDK installer for Windows provides java.exe, javaw.exe, javac.exe, and jshell.exe commands in a system location so that users can run Java applications without needing to provide the path to the Oracle JDK's installation folder.
7. JDK-8242060: A new
-revCheck
option has been added to the jarsigner
command to enable revocation checking of certificates.
8. JDK-8172404: The
keytool
and jarsigner
tools have been updated to warn users when weak cryptographic algorithms are used in keys, certificates, and signed JARs before they are disabled.
9. JDK-8172680: The SunJCE provider has been enhanced to support HmacSHA3-224, HmacSHA3-256, HmacSHA3-384, and HmacSHA3-512.
10. JDK-8242141: Two new system properties have been added to customize the TLS signature schemes in JDK.
jdk.tls.client.SignatureSchemes
has been added for the TLS client side, and jdk.tls.server.SignatureSchemes
has been added for the server side.
11. JDK-8206925: Now the "certificate_authorities" extension is supported for TLS 1.3 in both the client and the server sides.
12. JDK-8239385: The 'canonicalize' flag in the
krb5.conf
file is now supported by the JDK Kerberos implementation.
13. JDK-8005819: The support for the Kerberos MSSFU extensions [1] is now extended to cross-realm environments.
References
JDK 15 Release NotesJava Language Updates