keepcalculator

06 Numbers and Powers

Java 11 Key Features, Performance & Migration Checks

Card No. 06·39480 · Updated · Standard formula, shown below

Java 11, released in September 2018, is a long-term support (LTS) release that introduced several key features, notable performance improvements, and important migration considerations for developers upgrading from Java 8 or 9/10. This article explains the most significant changes, how they affect performance, and the checks you should perform before migrating.

Background: Why Java 11 Matters

Java 11 is the first LTS release after Java 8 under Oracle’s new six-month release cadence. Java 9 and 10 were short-lived feature releases, so many organizations jumped directly from Java 8 to Java 11. This makes understanding the differences between Java 8 and Java 11 particularly important. Java 11 also marked the end of the free Oracle JDK for commercial use, which pushed many teams toward OpenJDK builds or alternative distributions. The Java module system (Project Jigsaw) was introduced in Java 9, but Java 11 is the first LTS that includes it, so it is often the first time developers encounter modules in production.

Key Language and API Features

  • Local-Variable Syntax for Lambda Parameters – You can now use var in lambda parameters, e.g., (var x, var y) -> x + y. This allows annotations on lambda parameters without specifying the full type.
  • HTTP Client (Standard) – The new java.net.http.HttpClient became standard, supporting HTTP/2 and WebSockets. It provides a modern, asynchronous API that replaces the legacy HttpURLConnection for many use cases.
  • String Methods – New methods like isBlank(), lines(), strip(), stripLeading(), stripTrailing(), and repeat() simplify common string operations.
  • Files Methods – Files.readString() and Files.writeString() make reading and writing small text files much simpler.
  • Collection.toArray(IntFunction) – A new overloaded toArray method allows you to pass a generator function, e.g., list.toArray(String[]::new).
  • Optional.isEmpty() – A convenient way to check if an Optional is empty without negating isPresent().
  • Pattern.asMatchPredicate() – Useful for matching entire strings with a regex predicate.

Performance Changes and Improvements

Java 11 includes several performance enhancements, though many are incremental rather than dramatic. The most notable are:

  • Improved Garbage Collection – The G1 garbage collector became the default in Java 9 and was further refined in Java 11. G1 offers better pause-time control than the older parallel collector. Additionally, a new experimental garbage collector called ZGC (Z Garbage Collector) was introduced, designed for very large heaps with low latency, though it was experimental until Java 15.
  • JIT Compiler Enhancements – The Just-In-Time compiler saw improvements, including better inlining and optimizations. The Graal JIT compiler was available as an experimental option.
  • Reduced Memory Footprint – Some internal data structures were optimized, reducing memory usage in certain scenarios, especially with the new Compact Strings feature (introduced in Java 9) that stores strings as byte arrays when possible.
  • Faster Startup – While not a huge leap, the -XX:TieredStopAtLevel and other tuning options can help reduce startup time for small applications.
  • Improved Cryptography – The default TLS implementation was updated to support TLS 1.3, which offers better performance and security.

It is important to note that performance gains are application-specific. You should benchmark your own application before and after migration to see the actual impact.

Migration Checks: What to Verify Before Upgrading

Migrating from Java 8 (or earlier) to Java 11 requires careful planning. Here are the essential checks:

  1. Check for Removed APIs – Java 11 removed several deprecated APIs, including the Java EE modules (JAXB, JAX-WS, etc.) and the Nashorn JavaScript engine (though Nashorn was removed in Java 15, it was deprecated in 11). Use the jdeps tool to analyze your code for dependencies on these modules.
  2. Verify Third-Party Libraries – Some libraries may not be compatible with Java 11, especially if they use reflection on internal APIs. Check for updated versions or alternatives.
  3. Test with the Module System – If you are migrating from Java 8, your application will run on the classpath by default, but you should test it with the module path if you plan to modularize. Also, be aware that some libraries may not work well with modules.
  4. Update Build Tools and IDEs – Ensure your build tool (Maven, Gradle) and IDE support Java 11. You may need to update plugins and configurations.
  5. Check Garbage Collector Settings – If your application uses specific GC flags, they may have changed. G1 is the default now, so you might need to adjust heap sizes and pause-time goals.
  6. Review Security Manager – The Security Manager was deprecated in Java 17, but in Java 11 it is still present. However, some policies may behave differently.

Common Migration Problems and How to Solve Them

  • Missing Modules – The most common issue is java.lang.NoClassDefFoundError for JAXB or JAX-WS classes. Solution: add the corresponding dependencies manually, e.g., javax.xml.bind:jaxb-api.
  • Reflection Access Errors – Java 11 enforces strong encapsulation of internal APIs by default. If a library uses reflection on JDK internals, you may see IllegalAccessError. You can use --add-opens flags to temporarily open specific packages, but the long-term fix is to update the library.
  • Changed Default Charset – In Java 18, the default charset became UTF-8, but in Java 11 it is still platform-dependent. However, it is good practice to specify a charset explicitly to avoid locale issues.
  • G1 GC Pause Time – If your application experiences longer GC pauses after migration, tune the G1 parameters, such as -XX:MaxGCPauseMillis and -XX:G1HeapRegionSize.

Java 11 vs Java 8: A Quick Comparison

For many teams, the choice is between Java 8 and Java 11. Java 8 is stable and well-understood, but it is no longer publicly supported by Oracle (though other vendors offer extended support). Java 11 offers better performance, new language features, and long-term support. The main trade-offs are the migration effort and the learning curve for the module system. If you are starting a new project, Java 11 (or later LTS) is the recommended choice, but if you have a large legacy codebase, you may need to weigh the cost of migration against the benefits.

Cost and Support Considerations

Oracle’s JDK 11 is free for development and testing but requires a paid subscription for production use. However, many other vendors (such as Eclipse Adoptium, Amazon Corretto, and Azul Zulu) provide free, open-source builds of OpenJDK 11 with long-term support. This makes the cost of migrating less about licensing and more about the effort to update your code and infrastructure. When choosing a distribution, consider the support lifecycle and whether you need commercial support.

Frequently Asked Questions

Is Java 11 still supported?

Yes, but the support depends on the vendor. Oracle’s public updates for Java 11 ended in 2022, but you can still get extended support from Oracle with a paid subscription, or from other vendors like Adoptium, which offers free LTS support for many years.

Can I run Java 8 applications on Java 11?

Generally, yes, but you need to test thoroughly. Most Java 8 code will run on Java 11 without changes, but you may encounter issues with removed APIs or reflection. Use the jdeps tool to find potential problems.

What is the difference between Oracle JDK and OpenJDK?

Oracle JDK is the commercial distribution with a paid support model, while OpenJDK is the open-source reference implementation. Since Java 11, the two are essentially identical in functionality, with minor differences in packaging and support options.

How do I check if my application is compatible with Java 11?

Run jdeps --jdk-internals on your compiled classes to see if you use internal APIs. Also, run your test suite with Java 11 and monitor for any failures. Consider using a tool like Animal Sniffer to check for API compatibility.

What is the default garbage collector in Java 11?

The default is the G1 garbage collector. If you were using the parallel collector in Java 8, you may need to adjust your GC tuning flags to get the same performance.

Should I migrate to Java 11 or wait for a newer LTS?

If you are on Java 8, migrating to Java 11 is a good step because it is an LTS release and gives you a path to newer features. If you are already on Java 11, you might consider Java 17 (the next LTS) for even more improvements, but Java 11 remains a solid choice.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →