Wednesday 17 April 2013

Multitasking vs Multithreading or Advantages of Multithreading over Multitasking


Advantages of Multithreading:

  • Reduces the computation time.
  • Improves performance of an application.
  • Threads share the same address space so it saves the memory.
  • Context switching between threads is usually less expensive than between processes. 
  • Cost of communication between threads is relatively low.

What is Multithreading in Java


Multithreading :

  • Multithreading is a technique that allows a program or a process to execute many tasks concurrently (at the same time and parallel). 
  • It allows a process to run its tasks in parallel mode on a single processor system.
  • In the multithreading concept, several multiple lightweight processes are run in a single process/task or program by a single processor. 
  • For Example, When you use a word processor you perform a many different tasks such as printing, spell checking and so on. 
  • Multithreaded software treats each process as a separate program.
  • In Java, the Java Virtual Machine (JVM) allows an application to have multiple threads of execution running concurrently. 
  • It allows a program to be more responsible to the user. 
  • When a program contains multiple threads then the CPU can switch between the two threads to execute them at the same time

What is Multitasking in Java


Multitasking :

  • Multitasking allow to execute more than one tasks at the same time, a task being a program. 
  • In multitasking only one CPU is involved but it can switch from one program to another program so quickly that it gives the appearance of executing all the programs at the same time. 
  • Multitasking allow processes (i.e. programs) to run concurrently on the program. 
  • For Example running the spreadsheet program and you are working with word processor also.  
  • Multitasking is running heavyweight processes by a single OS.

Wednesday 10 April 2013

Exceptions in Java precise explanation


1)      The Throwable class is the superclass of all errors and exceptions in the Java language.
a)      Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.

2)      Both the classes Exception and Error is derived from Throwable interface.
3)      All exception classes are subtypes of the java.lang.Exception class.
a)      The two  main subclasses are IOException and RuntimeException.
4)      Errors are not normally trapped form the Java programs.
a)      These conditions normally happen in case of severe failures, which are not handled by the java programs. 
a)      If a method includes code that could cause a checked exception to be thrown then it is checked exception.
b)      Most of the built-in exceptions (e.g., NullPointerException, IndexOutOfBoundsException) are unchecked.