You are on page 1of 2

1) What is an exception?

Ans: Exception is an abnormal condition .it occurs during the program execution and disrupts the
normal flow of program.

2) How the exceptions are handled in java? OR Explain exception handling mechanism in
java?

Ans: try ,catch ,finally.

Try block is used to monitor the exception in this block.

Catch block is used to catches the exceptions in the try block.

Finally block is always executed whether exception occurred in the try block or not and occurred
exception is caught in catchblock.

3) What is the difference between error and exception in java?


Error Exceptions
Errors cannot be recovered. Exceptions can be recovered.
Errors are always unchecked. Exceptions are classified two
Checked Exception.
Unchecked Exception.
Error compiler won’t have knowledge Checked Exception compiler will
Of errors. Knowledge of checked
Exception.try,catch,finally.

4) What is the difference between checked and unchecked exception in java?

Checked unchecked

Checked exception are checked by unchecked exception are


The compiler.compile time unchecked by compiler it is also
exception . It is also known as run time
exception.
.Its propagate using throws keyword. .it is automatically propagated.

.Custom exception by extending .By extending runtime exception


java.lang.exception class. We can create custom exception.
File fast and File safe.

What is Concurrent Modification ?

When one or more thread is iterating over the collection, in between,


one thread changes the structure of the collection (either adding the
element to the collection or by deleting the element in the collection or
by updating the value at particular position in the collection) is known as
Concurrent Modification.

Fail Fast Vs Fail Safe Iterators In Java :

Fail-Fast Iterators Fail-Safe Iterators

it doesn’t allow modifications of a collection while It’s allow modifications of a collection while iterating

iterating over it. over it.

These iterators

throw ConcurrentModificationException if a collection is These iterators don’t throw any exceptions if a

modified while iterating over it. collection is modified while iterating over it.

They use original collection to traverse over the They use copy of the original collection to traverse over

elements of the collection. the elements of the collection.

These iterators require extra memory to clone the

These iterators don’t require extra memory. collection.

Ex : Iterators returned by ArrayList, Vector, HashMap. Ex : Iterator returned by ConcurrentHashMap.

You might also like