Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə29/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   25   26   27   28   29   30   31   32   ...   47
Java Interview Guide

Important Interfaces
Autocloseable
The Autocloseable interface is used in a try-with-resources block
to cleanup resources. Autocloseable defines a close() method that
is invoked by the JVM after a try-with-resources block completes.


Comparable
The Comparable interface determines the natural ordering between objects
of the same type. Comparable defines a generic compareTo(T) method
that returns an integer indicating whether an object is less than, equal to,
or greater than a comparable object. A list of Comparable objects can
be sorted in the Collections#sort(List) method.


Comparator
The Comparator interface determines a sorting strategy between objects
of the same type. This can be used to sort objects that do not implement
Comparable
, or to sort objects in a manner distinct from their natural
ordering. Comparator defines a generic compare(T, T) method that
returns an integer indicating whether the first object is less than, equal to,
or greater than the second object. Lists can be sorted by comparators in the
Collections#sort(List, Comparator)
method.


Iterable
The Iterable interface defines a method that returns an Iterator.
An object that implements Iterable can be used in an enhanced for-loop.
Note that although arrays can be used in enhanced for-loops, they do not
implement the Iterable interface.


Runnable
The Runnable interface encapsulates an action that runs inside of a thread.
Runnable
defines a run() method that is invoked by the thread scheduler
after a thread transitions into a runnable state.


Callable
The Callable interface encapsulates a task that runs inside of a thread and
computes a result. Callable defines a generic call() method that returns
a result or throws an exception. Callable is used throughout the
executor framework.


Serializable
The Serializable interface is a marker which indicates that an object
is eligible for serialization. Serialization is the process of converting an object
into bytes that can be stored on a filesystem or streamed over a network. Objects
can provide custom serialization logic by implementing three special private
methods: writeObject(), readObject(),
and readObjectNoData(). Every serializable class is assigned
a configurable version number called serialVersionUID that is used to ensure
compatibility during the deserialization process.


Questions
What is the Autocloseable interface?
What is the Comparable interface?
What is the Comparator interface?
What is the Iterable interface?
What is the Runnable interface?
What is the Callable interface?
What is the Serializable interface?



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   25   26   27   28   29   30   31   32   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin