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.
Showing posts with label Program. Show all posts
Showing posts with label Program. Show all posts
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.
Dynamic Stack in Java
Stack is one of the basic data structure in any programming language. In this article, I would try to make you understand stack and then, I would share a Java program that implements fixed size stack. Stack is the structure that implements last in first out elimination technique. A stack has two operations that can be operated on it. They are, push and pop. In push method, we put an item on the top of the top and pop operation removes the item currently one the top of the Stack.
Stack in Java
Stack is one of the basic data structure in any programming language. In this article, I would try to make you understand stack and then, I would share a Java program that implements fixed size stack. Stack is the structure that implements last in first out elimination technique. A stack has two operations that can be operated on it. They are, push and pop. In push method, we put an item on the top of the top and pop operation removes the item currently one the top of the Stack.
How to return Objects from Methods
Java enables us to return objects from the methods as well. Returning and passing objects need to consider the parent child relationship among the classes. This relationship holds importance because, as a matter of fact, Object of parent class can hold the address of object of child class.
Java program to check whether a number is palindrome or not
Checking whether a number is palindrome or not, is one of the earlist classic problem in programming. A number is said to be palindrome if on reversing the number, we get the same number. For example, consider the number 121, on reversing we get 121. So, it is a palindrome number. Java program to check whether a number is palindrome or not is given.
Fibonacci series program in Java
Fibonacci series is one the most series es in the world. In a Fibonacci series, each term is the sum of last two terms. For the first two terms, 1st is taken as 0 and second is taken as 1. Fibonacci series has attracted a lot of attention and research. So. let us devote a JAVA program to print the Fibonacci series.
Java program to reverse a number
Java program to reverse a number is one of the simplest programming problems. The JAVA program that reverses a number is given.
How to use Objects as Parameter
The first thing that anyone needs to know is the difference between argument and parameters. Arguments are the variables that are passed to the functions and parameters are the variables that receive the value of the arguments. Java rich Object Oriented Features allow us to use Objects as the parameter.
Recursive Factorial Program in Java
Recursion is the process in which a function calls itself. Generally, iterative programs are slower than corresponding iterative versions of the same program but recursion has found its use due to the fact that sometimes, it is easier to develop recursive version of the program than to develop a iterative version of the same program. The general condition for the recursive program is to have a condition that should fail at some point in the program and at that point, the program needs to traverse back to generate the final answer. Without this condition, your program may fall into an infinite loop, so, the program will never stop unless the stack of method calls is overflowed.
Factorial Program in Java
In mathematics, the factorial of the number is defined as
n! = n*(n-1)*(n-2)*(n-3)*(n-4)*...1
n! = n*(n-1)*(n-2)*(n-3)*(n-4)*...1
Method Overloading Demystified
Method Overloading is one of the best features of the Object Oriented Language. With Method Overloading, Java implements Polymorphism.
Garbage Collector Program in JAVA
Java language dynamically allocates the memory to the objects of the classes being used in the program. Unlike C++ where a destructor is needed to free the memory, JAVA employs Garbage Collector Mechanism to reclaim the allocated memory. When no referance to the object exists in the memory, it becomes eligible to be collected by Garbage Collector.
The finalize method provided by java sees to it that this method is executed just before the memory allocated to the object is being reclaimed. There is no gurantee that a finalize method would be executed. My aim was to observe the functioning of the garbage collector. So, I created a program. And here it is.
Subscribe to:
Posts (Atom)