Java 15 Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. What is the Garbage Collector ZGC + Shenandoah in Java 15?
The requirements for modern applications are becoming increasingly demanding. With memory requirements ranging from gigabytes to terabytes, they may have to achieve response times in the single-digit millisecond range.
Conventional garbage collectors (such as the allrounder G1) with stop-the-world phases of a hundred milliseconds and more are not optimally suited to such requirements.
Aiming to eliminate stop-the-world pauses as much as possible (by doing most of the work in parallel with the running application), or at least reduce them to a few milliseconds, Oracle and RedHat have developed two new garbage collectors that have been shipped as preview features since Java 11 and 12, respectively.
As of Java 15, they are ready for productive use and will hopefully make the Java platform attractive to even more developers.
Ques 2. What is String.stripIndent() in Java 15?
Suppose we have a multi-line string where each line is intended and has some trailing spaces, such as the following. We print each line, bounded by two vertical bars.
String html = """
<html> s
<body> s
<h1>Hello!</h1>
</body> s
</html> s
""";
html.lines()
.map(line -> "|" + line + "|")
.forEachOrdered(System.out::println);
Code language: Java (java)
As you learned in the first chapter, the alignment of a text block is based on the closing quotation marks. The output, therefore, looks like this:
| <html> |
| <body> |
| <h1>Hello!</h1>|
| </body> |
| </html> |
Using the stripIndent()
method, we can remove the indentation and trailing spaces:
html.stripIndent()
.lines()
.map(line -> "|" + line + "|")
.forEachOrdered(System.out::println);
The output is now:
|<html>|
| <body>|
| <h1>Hello!</h1>|
| </body>|
|</html>|
Ques 3. What is the change of Helpful NullPointerExceptions in Java 15?
Helpful NullPointerExceptions, introduced in Java 14, are enabled by default in Java 15 and later.
"Helpful NullPointerExceptions" no longer only show us in which line of code a NullPointerException occurred, but also which variable (or return value) in the corresponding line is null and which method could therefore not be called.
You can find an example in the article linked above.
Ques 4. What are Specialized Implementations of TreeMap Methods in Java 15?
In TreeMap, specialized methods putIfAbsent(), computeIfAbsent(), computeIfPresent(), compute(), and merge() were implemented.
These methods were only specified as default methods in the Map interface since Java 8.
The TreeMap-specific implementations are optimized for the underlying red-black tree; accordingly, they are more performant than the interface's default methods.
Ques 5. What are the Deprecations and Deletions in Java 15?
- Remove the Nashorn JavaScript Engine
- Remove the Solaris and SPARC Ports
- Deprecate RMI Activation for Removal
Most helpful rated by users:
- What is Java 15?
- What is Text Blocks or Multi-line string in Java 15?
- What are New String and CharSequence Methods in Java 15?
- What is CharSequence.isEmpty() in Java 15?
- Provide the release notes of Java 15.