What is new in Java 21? Flashcards
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
c) It abstracts operating system threads using virtual threads
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()
c) Thread.startVirtualThread()
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) It requires fewer resources from the operating system
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
b) Virtual threads cannot adjust their priority
Which of the following methods does not exist for Sequenced Collections in Java 21?
a) addFirst()
b) getFirst()
c) removeLast()
d) shuffle()
d) shuffle()
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
b) It tracks the order in which elements are added
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()
c) firstEntry()
In Java 21, which method would you use to reverse the order of a SequencedCollection?
a) reverseOrder()
b) reorderCollection()
c) reversed()
d) reverseSequence()
c) reversed()
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
b) It simplifies string concatenation and runtime expression injection
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) Using the + operator or StringBuilder
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()
c) { } expression embedding
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
b) It offers a simpler and more readable approach