What is new in Java 21? Flashcards

1
Q

What significant change does virtual threading in Java 21 bring to concurrency?

a) It replaces the JVM with a new runtime
b) It introduces a new form of sequential processing
c) It abstracts operating system threads using virtual threads
d) It removes multi-threading capabilities from Java

A

c) It abstracts operating system threads using virtual threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What method would be used to start a virtual thread in Java 21?

a) Thread.start()
b) Thread.runVirtualThread()
c) Thread.startVirtualThread()
d) Thread.initiateVirtualThread()

A

c) Thread.startVirtualThread()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a key advantage of using virtual threads compared to traditional OS-level threads?

a) It requires fewer resources from the operating system
b) It makes applications slower but more reliable
c) It reduces the flexibility of thread management
d) It prioritizes OS threads over Java threads

A

a) It requires fewer resources from the operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Java 21, what restriction applies to virtual threads?

a) Virtual threads cannot be used in multithreaded environments
b) Virtual threads cannot adjust their priority
c) Virtual threads can only run one at a time
d) Virtual threads do not work with the JVM

A

b) Virtual threads cannot adjust their priority

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following methods does not exist for Sequenced Collections in Java 21?

a) addFirst()
b) getFirst()
c) removeLast()
d) shuffle()

A

d) shuffle()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the SequencedCollection interface improve working with collections in Java 21?

a) It allows elements to be sorted by size
b) It tracks the order in which elements are added
c) It provides automatic error checking for lists
d) It eliminates the need for unique keys in maps

A

b) It tracks the order in which elements are added

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which new method is used to retrieve the first entry in a map collection in Java 21?

a) getFirstEntry()
b) retrieveFirst()
c) firstEntry()
d) accessFirstEntry()

A

c) firstEntry()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In Java 21, which method would you use to reverse the order of a SequencedCollection?

a) reverseOrder()
b) reorderCollection()
c) reversed()
d) reverseSequence()

A

c) reversed()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the primary benefit of using string templates in Java 21?

a) It reduces memory usage in strings
b) It simplifies string concatenation and runtime expression injection
c) It allows strings to be compiled at runtime
d) It eliminates the need for variables in strings

A

b) It simplifies string concatenation and runtime expression injection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What was the traditional way to concatenate strings before string templates in Java 21?

a) Using the + operator or StringBuilder
b) Using the append() method only
c) Using arrays of characters
d) Using runtime evaluators

A

a) Using the + operator or StringBuilder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which feature of string templates in Java 21 allows variables to be embedded in strings?

a) STR.compile()
b) STR.templates()
c) { } expression embedding
d) STR.run()

A

c) { } expression embedding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does the use of string templates compare to traditional string building methods in Java?

a) It provides more complexity
b) It offers a simpler and more readable approach
c) It limits the flexibility of strings
d) It increases the lines of code

A

b) It offers a simpler and more readable approach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly