I have shared enough theory on Multi-Threading in my previous post. Now, it is time to share code for Multi-Threaded programs by implementing runnable interface.
Multithreading by Extending Thread Class
Multi-threading is a topic, that I found most difficult to understand. First thing that needs to be understood is the distinction between a Thread and a Program. Thread is the smallest unit of execution. A program may contain more than one thread that executes concurrently. Let me tell you that saying concurrent execution is not correct, a computer processor can execute only one process at a time (single core processors), and if a process involves more than one Thread, only one Thread, would execute at a time, when a Thread gets paused, then and then only, any other Thread can start executing. If you ask what exactly is the advantage of multi-threading, then the advantage of multi-threading is that you can assign different tasks to Threads, for example, As in Android, Image Retrieval from database is time consuming and processor intensive task, so it is preferred to implement image retrieval mechanism on a separate thread.
- Written Under Demystified, Multi, Multi-Threding, Program, Thred, Tutorial
Chained Exceptions in Java
Chained Exceptions were introduced in Java with JDK 1.4. In Chained exceptions, we can associate an exception with some other exception so that it can be inferred that occurrence of one exception is due to associated exception in reality.
Creating Your own Exceptions in Java
An exception is generally a run time error that leads to unwanted instant termination of the program. An exception must be handled, failing to do so leads to transfer of control of execution to Java's default exception handler. In this article, I would try to develop an exception which is generated if you use a special name "HERR".
Extended Interface in Java
Interfaces just like classes in Java, can be extended. A class implementing the outer interface must implement all the methods of the super class. A class implementing the sub interface must implement all the methods of sub interface as well as methods of super interface. If it fails to do so, compiler reports an error, that it should either implement the missing method or declare itself as Abstract.
Nested Interface
Interfaces in Java, just like classes can be nested. An interface declared inside body of another interface is called nested interface. However, the two interfaces exists independently in terms of implemention. It means that one does not needs to implement the methods of both the interface if one implements only one of them. However, inner interface cant exist on its own,
Subscribe to:
Posts (Atom)