Posts

Showing posts from 2016

Exception Handling in Java

Image
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.  When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception. After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible "somethings" to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. Java defines several exception classes inside the standard package java.lang. The most general of these exceptions are subclasses of the standard type RuntimeException. Since java.lang is implicitly imported into all Java programs, ...

Split digit in java

Image
Below sample program can be used to split number into digits. Here we are using a 4 digit number to do the same. class Split { public static void main(String args[]) { int a=1234,r=0; while(a!=0) { r=a%10; a=a/10; System.out.println(r+""); } } } Output:

MultiThreading in Java

Image
Multithreading is a type of execution model that allows multiple threads to exist within the context of a process such that they execute independently but share their process resources. A thread maintains a list of information relevant to its execution including the priority schedule, exception handlers, a set of CPU registers, and stack state in the address space of its hosting process. Multithreading is also known as threading. Following are some of the common advantages of Multithreading: Enhanced performance by decreased development time Simplified and streamlined program coding Improvised GUI responsiveness Simultaneous and parallelized occurrence of tasks Better use of cache storage by utilization of resources Decreased cost of maintenance Better use of CPU resource Multithreading does not only provide you with benefits, it has its disadvantages too. Let us go through some common disadvantages: Complex debugging and testing processes Overhead switching of cont...