OOP 1 - Unit 4
OOP 1 - Unit 4
What is Exception
An exception is unexpected, unwanted, abnormal situation that occur
at runtime is call exception.
Throws Keyword
The Java throws keyword is used to declare an exception. It gives an
information to the programmer that there may occur an exception.
Finally Block
Finally block is a real time block and the main purpose of finally block
to handle the resources.
Finally block is always execute
if there is an exception occur or not occur.
Finally block is a real time block and the main purpose of finally block
to handle the resources.
Exception Hierarchy
1. Exception
2. Error
Throwable
Exception Error
1. RuntimeException 1. StackOverflowError
2. IO Exception 2. OutOfMemoryError
3. SQL Exception 3. IOError
4. Interrupted Exception 4. LinkageError
5. ClassNotFouneException
6. Etc...
Exception
Home Work
Checked and unchecked exception hierarchy.
Multithreading
Multithreading
Multithreading is a process to execute multiple threads at the same time
without dependency of other threads called multithreading.
Thread
Thread is a lightweight process, It is a pre defined class in java which is
available in java.lang package.
Thread is a basic unit of CPU and it is well known for independent
execution.
A thread is an independent path of execution in java.
Thread is a line of execution in a program.
A thread in java helps to achieve multithreading in java.
The main method is also knows as the main thread of execution.
The JVM or java virtual machine allows an application to execute
multiple threads within a program concurrently.
When we start the JVM, a single thread (main) started by main( )
method.
How to create Thread in JAVA?
Waiting
t.start( ) TS
Born Runnable Running Dead
t.stop( )