Description
3.1 Errors and Exception
Errors:
- Compile-time errors: Syntax errors.
- Runtime errors: Logic errors, exceptions.
- Logical errors: Incorrect program logic.
Exceptions:
- Exception handling: Managing runtime errors.
tryblock: Code that might throw an exception.catchblock: Handles a specific exception.finallyblock: Code that always executes.throwskeyword: Declares an exception.throwkeyword: Throws an exception.- Built-in exceptions:
IOException,SQLException,ArithmeticException. - Custom exceptions: User-defined exceptions.
3.2 Multithreaded programming
Creating a Thread:
Threadclass: Extending theThreadclass.Runnableinterface: Implementing theRunnableinterface.run()method: Contains thread’s code.start()method: Starts thread execution.
Thread Life Cycle:
- New: Just created.
- Runnable: Ready to run.
- Running: Currently executing.
- Blocked/Waiting: Paused, waiting for an event.
- Terminated/Dead: Finished execution.
Thread Methods:
sleep(): Pauses thread.join(): Waits for a thread to finish.yield(): Gives up CPU time.interrupt(): Interrupts a thread.
Synchronization:
synchronizedkeyword: Prevents simultaneous access.- Race condition: Multiple threads accessing shared data.
- Deadlock: Two or more threads blocked indefinitely.





Reviews
There are no reviews yet.