Sitemap
Pravinkumar Singh

Pravinkumar Singh

Engineer & Explorer https://www.linkedin.com/in/iampravo/

JAVA-RELEASE/JAVA-10

Java 10: Quick Walkthrough

This article covers features of Java 10 with code examples

4 min readJun 14, 2023

--

Press enter or click to view image in full size
image by Pravinkumar Singh

Hey wassup, Java developers! Keeping up with Java’s rapid release cycle can be quite challenging. But fikar not, we are here to discuss Java 10 and the features it brings to the table.

Java 10: Major Additions

Java 10 was released in March 2018, just six months after the release of Java 9, with a variety of small changes and enhancements. Let’s examine some of the significant additions and enhancements in Java 10:

1. Local Variable Type Inference (JEP 286)

In Java 10, you can use the var keyword to declare local variables without explicitly specifying their type. The compiler will infer the variable's type based on the value it is assigned.

Here’s how it works — before Java 10, we would declare a variable like this:

List<String> names = new ArrayList<>();

From Java 10 onwards, you can use var instead:

var names = new ArrayList<String>();

The compiler will automatically infer the type of names as List<String>. sounds good, right?

However, when using var, there are a few things to keep in mind. You must initialize the variable when declaring it, and you cannot use null as the initializing value. Also, remember that var can only be used with local variables.

Keep in mind that the goal of using var is to make your code cleaner and easier to understand. If the variable's purpose is not immediately used, then stick to explicitly declaring the type.

2. Consolidating the JDK Forest into a Single Repository (JEP 296)

Before Java 10, the JDK source code was divided into multiple repositories, each dedicated to a specific purpose. Maintaining these disparate repositories could be cumbersome and confusing. To simplify this, Java 10 consolidates the different repositories into a single one, making the JDK source code and build system much more manageable.

This change doesn’t directly impact Java developers, but it makes things easier for those working on the JDK itself.

3. Application Class-Data Sharing (JEP 310)

Class-Data Sharing (CDS) improves the startup performance of applications and reduces the memory footprint. In earlier versions, CDS was limited to system classes of the JDK.

Java 10 extends CDS to include application classes, enabling developers to include their application classes in a shared archive to leverage the optimization CDS provides. Sharing classes more efficiently between JVM instances leads to reduced memory usage and shorter startup times.

Get Pravinkumar Singh’s stories in your inbox

Join Medium for free to get updates from this writer.

To use Application Class-Data Sharing, perform the following steps:

  1. Run your application with the -XX:DumpLoadedClassList=<class-list-file> option:
java -XX:DumpLoadedClassList=myapp.lst -cp myapp.jar MyApp

2. Create a shared archive using the -Xshare:dump option:

java -Xshare:dump -XX:SharedClassListFile=myapp.lst -XX:SharedArchiveFile=myapp.jsa -cp myapp.jar

3. Launch your application with the -Xshare:on option:

java -Xshare:on -XX:SharedArchiveFile=myapp.jsa -cp myapp.jar MyApp

4. Garbage-Collector Interface (JEP 304)

Garbage Collector (GC) implementations in the JVM have been difficult to manage due to their close coupling with the rest of the JVM. Java 10 introduces better modularity by providing a clean Garbage-Collector interface, thus enhancing the maintainability of the JVM code.

This enhancement doesn’t directly impact everyday Java developers, but those working on adding, modifying, or maintaining Garbage Collectors in the JDK will appreciate this change.

5. Remove the Native-Header Generation Tool (javah) (JEP 313)

The javah tool was used to generate C header files from a Java class, but its functionality was largely superseded by the -h option in javac. JEP 313 removed the javah tool from the JDK. If you were using javah, you can replace it with javac -h.

6. Parallel Full GC for G1 (JEP 307)

The G1 garbage collector was designed to avoid full GCs, but when a full GC did occur, it was done in a single-threaded manner. JEP 307 made the full GC phase parallel, which can significantly reduce the time required for full GCs and thus improve application performance.

7. Thread-Local Handshakes (JEP 312)

This feature introduces a way to execute a callback on threads without performing a global VM safepoint, making it possible to stop individual threads and not just all of them. This mechanism is a building block for future features and improvements, such as improved VM performance, faster object layout changes, and more.

8. Additional Unicode Language-Tag Extensions (JEP 314)

This JEP enhances java.util.Locale and related APIs to implement additional Unicode extensions of BCP 47 language tags. This allows Java applications to recognize more language, script, region, and variant information from locale tags.

9. Heap Allocation on Alternative Memory Devices (JEP 316)

This feature enables the HotSpot VM to allocate the Java object heap on an alternative memory device, such as an NV-DIMM, specified by the user. This can be useful for configurations where a large heap is required, but not all of the heap needs to be on DRAM.

10. Experimental Java-Based JIT Compiler (JEP 317)

This JEP integrates the Graal dynamic compiler for the Linux x64 platform into the JDK as an experimental feature. The Graal compiler is a new JIT compiler that aims to improve the performance of Java applications.

11. Root Certificates (JEP 319)

This JEP provides a default set of root Certification Authority (CA) certificates in the JDK. This makes it more convenient for developers as they don't have to manage their own set of root certificates. It also enhances security as the certificates are vetted by the OpenJDK community.

Wrapping It Up

As we can see, Java 10 has introduced some interesting updates that simplify code writing and improve the overall performance of our Java applications. While many of these changes will primarily benefit

Peace!

Related reads : java-release

--

--