Wednesday, 17 April 2013

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.

Wednesday, 27 March 2013

What is a Diamond problem in java? Why multiple inheritance is not supported in java?


Consider a class A has foo() method and then B and C derived from A and has their own foo() implementation.
Now class D derive from B and C using Multiple inheritance and if we refer just foo() compiler will not be able to decide which foo() it should invoke.
This is called as Diamond problem because structure on this inheritance scenario is similar to four edge diamond.
Also multiple inheritance causes problem in Constructor chaining, Casting.

Can you override static method in Java?


No. We can not override static method in java.
Overriding depends on having an instance of a class.
The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses).
A static method is not associated with any instance of a class so the concept is not applicable.

Can you access non Static variable in Static block?

No. Only static variables can be accessed in static block.

Will finally block execute ,if System.exit is called in try or catch block?

No. Finally block won't run if you call System.exit form try catch.

Will finally block execute ,if a return statement is called in try or catch block?

Yes. The finally block will execute even if there is return statement in try or catch block.