Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Strawberry. So, the replace method at Line 3 does not replace the value since the key 3


Download 1.52 Mb.
Pdf ko'rish
bet99/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   95   96   97   98   99   100   101   102   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Strawberry. So, the replace method at Line 3 does not replace
the value since the key 3 is not mapped to Blackberry.
Explain the differences between an Iterator and
SplitIterator.
Answer:
Both the Iterator and SplitIterator can be used for iterating
through the elements in a Collection. However, there are some
differences between these interfaces. These are as follows:
The Iterator interface is present right from the earlier versions
of Java. The SplitIterator is a new interface added by Java 8.
The Iterator interface only supports sequential processing.
The SplitIterator supports both sequential as well as parallel
processing.
The Iterator can be used for iterating over a Collection. The
SplitIterator can be used for iterating over a Collection as well
as a Stream.



The Iterator only allows traversing over the elements of a
Collection individually. The SplitIterator on the other hand
allows traversing over the elements of a Collection individually
as well as in bulk.



257.



CHAPTER
09
Miscellaneous
What are the advantages of CompletableFuture class over
the Future Interface?
Answer:
Prior to Java 8, Java had the Callable class and the Future
interface. These could be used to return the result of an
asynchronous computation. However, the Future interface had
several issues. The CompletableFuture overcomes all these
issues as follows:
A Future cannot be completed manually. So, if a task is
hung, there is no way of completing the task manually.
CompletableFuture on the other hand has a method
called complete() that allows completing a task manually.
Future has a method called get() that returns the result of
computation. However, this method blocks until the result
becomes available. So, if you want to perform any
computation on the result of the Future, you need to wait for
the result to be available. A CompletableFuture on the
other hand allows attaching callbacks to the result of a
computation. These callbacks execute once the result is
available, so there is no need to wait.
The Future interface does not have any exception handling
mechanism. The CompletableFuture on the other hand
has a method called exceptionally() that allows running
alternate code in case an exception occurs.



Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   95   96   97   98   99   100   101   102   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling