Prepare Interview

Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java 15 Interview Questions and Answers

Freshers / Beginner level questions & answers

Ques 1. What is Java 15?

Released on September 15, 2020.

There are a few new features and updates have been provided here:

The JDK class library, Text Blocks, performance changes, experimental, preview, and incubator features, deprecations and deletions, and finally, other changes that we rarely come into contact with.

But that's not all: A total of 14 JDK Enhancement Proposals (JEPs) have made it into this release.

Is it helpful? Add Comment View Comments
 

Ques 2. What is Text Blocks or Multi-line string in Java 15?

Until now, when we wanted to define a multi-line string in Java, it usually looked like this:

String sql =
" SELECT id, title, text\n"
+ " FROM Article\n"
+ " WHERE category = \"Java\"\n"
+ "ORDER BY title";

Starting with Java 15, we can notate this string as a "text block":

String sql = """
SELECT id, title, text
FROM Article
WHERE category = "Java"
ORDER BY title""";

Is it helpful? Add Comment View Comments
 

Ques 3. What are New String and CharSequence Methods in Java 15?

  • String.formatted()
  • String.stripIndent()
  • String.translateEscapes()
  • CharSequence.isEmpty()

Is it helpful? Add Comment View Comments
 

Ques 4. 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.

Is it helpful? Add Comment View Comments
 

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

Is it helpful? Add Comment View Comments
 

Ques 6. 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.

Is it helpful? Add Comment View Comments
 

Ques 7. Provide the release notes of Java 15.

The details are provided here.

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

Related differences

Java 14 vs Java 15Java 15 vs Java 16

Related interview subjects

Core Java interview questions and answers - Total 306 questions
Tomcat interview questions and answers - Total 16 questions
Apache Wicket interview questions and answers - Total 26 questions
Java Applet interview questions and answers - Total 29 questions
JAXB interview questions and answers - Total 18 questions
JMS interview questions and answers - Total 64 questions
Log4j interview questions and answers - Total 35 questions
Struts interview questions and answers - Total 84 questions
RMI interview questions and answers - Total 31 questions
Apache Camel interview questions and answers - Total 20 questions
JDBC interview questions and answers - Total 27 questions
Java 11 interview questions and answers - Total 24 questions
JPA interview questions and answers - Total 41 questions
EJB interview questions and answers - Total 80 questions
GWT interview questions and answers - Total 27 questions
Kotlin interview questions and answers - Total 30 questions
Glassfish interview questions and answers - Total 8 questions
Google Gson interview questions and answers - Total 8 questions
JSP interview questions and answers - Total 49 questions
J2EE interview questions and answers - Total 25 questions
Apache Tapestry interview questions and answers - Total 9 questions
Java Swing interview questions and answers - Total 27 questions
Java Mail interview questions and answers - Total 27 questions
Hibernate interview questions and answers - Total 52 questions
JSF interview questions and answers - Total 24 questions
Java 8 interview questions and answers - Total 30 questions
Java 15 interview questions and answers - Total 16 questions
JBoss interview questions and answers - Total 14 questions
Web Services interview questions and answers - Total 10 questions
RichFaces interview questions and answers - Total 26 questions
Servlets interview questions and answers - Total 34 questions
Java Beans interview questions and answers - Total 57 questions
Spring Boot interview questions and answers - Total 50 questions
JUnit interview questions and answers - Total 24 questions
Spring Framework interview questions and answers - Total 53 questions
Java Design Patterns interview questions and answers - Total 15 questions
©2023 WithoutBook