Unit IV 2 Marks Copy
Unit IV 2 Marks Copy
UNIT IV
PART A
Sl. No. Questions
1. What is an exception? Give example.
Exception is a mechanism which is used for handling unusual situation that may occur in
the program. For example -
ArithmeticException: This exception is used to handle arithmetic exceptions such as
divide by zero.
IOException: This exception occurs when an illegal input/output operation is performed.
2 Unchecked Exception: These type of exceptions need not be handled explicitly. The Java
Virtual Machine handles these type of exceptions. These exceptions are extended from
java.lang.RuntimeException class.
For example: ArrayIndexOutOfBounds, NullPointerException, RunTimeException.
10. Can we have empty catch block?
Yes we can have empty catch block, but it is an indication of poor programming practice.
We should never have empty catch block because if the exception is caught by that block,
we will have no information about the exception and it will create problem while
debugging the code.
PART B
1. Define Exception.Discuss about exception hierarchy in Java with example.
2. Explain types of exceptions with example programs. [Checked Exception & Unchecked
Exception]
3. Explain the five keywords in exception handling with necessary syntax and examples.
4. Explain in detail about User-Defined Exception with Example Program.
7. Show how to extend Thread class and how to implement the runnable interface for creating and
starting threads.
8. Describe the creation of a single thread and multiple threads using an example.
10. Create a simple real life application program in Java to illustrate the use of multithreads.