Collections Exceptions Interview Questions
Collections Exceptions Interview Questions
Exceptions Interview
Preparations
Question
1. What are exceptions in java and how do you handle them?
Exceptions occur when there is an issue with the program. There are two types of
exceptions: Checked exceptions (aka Compile time) and Unchecked exceptions
(aka Runtime). All checked exceptions must be handled otherwise the program will
not compile. Unchecked exceptions happen during runtime so if they occur the
program will be interrupted during execution making these exceptions are more
difficult to handle.
Exceptions can be handled using the try/catch block which lets you define the
actions taken if specific exceptions occur. It is also possible to use the keyword
throws in the method signature to allow the program to compile and accept that an
exception may occur, but this is not handling the exception.
The collection framework is a group of interfaces and concrete classes that are different
data structures used to solve different problem.
Hashtable
o Same as HashMap BUT HashTable methods are
synchronized (REMEMBER. ONLY METHODS ARE
SYNCHRONIZED, NOT CLASSES OR VARIABLES)
o Hashtable won't let you have anything NULL (NO NULLS AT
ALL)
LinkedHashMap
oMaintains insertion order (or optionally, access order)
o Slower than HashMap for adding/removing elements but
FASTER ITERATION
SortedMap:
o TreeMap: Keys are sorting in natural order