Die meistgefragten Interviewfragen und Antworten sowie Online-Tests
Lernplattform fur Interviewvorbereitung, Online-Tests, Tutorials und Live-Ubungen

Baue deine Fahigkeiten mit fokussierten Lernpfaden, Probetests und interviewreifem Inhalt aus.

WithoutBook vereint themenbezogene Interviewfragen, Online-Ubungstests, Tutorials und Vergleichsleitfaden in einem responsiven Lernbereich.

Interview vorbereiten

Probeprufungen

Als Startseite festlegen

Diese Seite als Lesezeichen speichern

E-Mail-Adresse abonnieren

Java 15 Interviewfragen und Antworten

Verwandte Vergleiche

Java 14 vs Java 15Java 15 vs Java 16

Frage 1. What is String.formatted() in Java 15?

We could previously replace placeholders in a string as follows, for example:

String message =    String.format(        "User %,d with username %s logged in at %s.",        userId, username, ZonedDateTime.now());

Starting from Java 15, we can use an alternative syntax:

String message =    "User %,d with username %s logged in at %s."        .formatted(userId, username, ZonedDateTime.now());

It makes no difference which method you use. Both methods will eventually call the following code:

String message =    new Formatter()        .format(            "User %,d with username %s logged in at %s.",            userId, username, ZonedDateTime.now())        .toString();

So the choice is ultimately a matter of taste. I quickly made friends with the new spelling.

Ist das hilfreich? Kommentar hinzufugen Kommentare ansehen
 

Frage 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>|

Ist das hilfreich? Kommentar hinzufugen Kommentare ansehen
 

Frage 3. What is String.translateEscapes() in Java 15?

Occasionally we get to deal with a string that contains escaped escape sequences, such as the following:

String s = "foo\\nbar\\tbuzz\\\\";System.out.println(s);

The output looks like this:

foo\nbar\tbuzz\\

Sometimes, however, we want to display the evaluated escape sequences: a newline instead of "\n", a tab instead of "\t", and a backslash instead of "\".

Until now, we had to rely on third-party libraries such as Apache Commons Text for this:

System.out.println(StringEscapeUtils.unescapeJava(s));

Starting from Java 15, we can avoid the additional dependency and use the JDK method String.translateEscapes():

System.out.println(s.translateEscapes());

The output now reads:

foobar     buzz

Ist das hilfreich? Kommentar hinzufugen Kommentare ansehen
 

Frage 4. What is CharSequence.isEmpty() in Java 15?

Also new is the default method isEmpty() in the CharSequence interface. The method simply checks whether the character sequence's length is 0:

default boolean isEmpty() {  return this.length() == 0;}

This method is thus automatically available in the Segment, StringBuffer, and StringBuilder classes.

String and CharBuffer, which also implement CharSequence, each have their optimized implementation of isEmpty(). With String, for example, the call to length() is unnecessarily expensive because, since Java 9 (JEP 254 "Compact Strings"), the string's encoding must also be taken into account when calculating its length.

Ist das hilfreich? Kommentar hinzufugen Kommentare ansehen
 

Frage 5. 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.

Ist das hilfreich? Kommentar hinzufugen Kommentare ansehen
 

Am hilfreichsten laut Nutzern:

Copyright © 2026, WithoutBook.