java4all@1986 java. Powered by Blogger.

>> Saturday, June 25, 2011

Q).What are different type of exceptions in Java?
A).
There are two types of exceptions in java. Checked exceptions and Unchecked exceptions. Any exception that is is derived from Throwable and Exception is called checked exception except RuntimeException and its sub classes. The compiler will check whether the exception is caught or not at compile time. We need to catch the checked exception or declare in the throws clause.  Any exception that is derived from Error and RuntimeException is called unchecked exception. We don't need to explicitly catch a unchecked exception.

Q).Can we catch an error in our java program ?
A).
Yes. We can . We can catch anything that is derived from Throwable. Since Error is a sub class of Throwable we can catch an error also.

Q).What is thread priority?
A)
.Thread Priority is an integer value that identifies the relative order in which it should be executed with respect to others. The thread priority values ranging from 1- 10 and the default value is 5. But if a thread have higher priority doesn't means that it will execute first. The thread scheduling depends on the OS.
   
Q).How many times may an object's finalize() method be invoked by the garbage collector?
A).
Only once.

Q).What must a class do to implement an interface?
A).
It must identify the interface in its implements clause. Also it must provide definition for all the methods in the interface otherwise it must be declared abstract.
       
Q).What is the difference between notify and notifyAll method ?
A)
.notify wakes up a single thread that is waiting for object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

Q).What does wait method do ?
A).
It causes current thread to wait until either another thread invokes notify or notifyAll method of the current object, or a specified amount of time has elapsed.

Q).What are the different states of a thread ?
A).
The different thread states are ready, running, waiting and dead.
   
Q).What is the difference between String and StringBuffer class ?
A)
.Strings are immutable (constant), their values cannot be changed after they are created. StringBuffer supports mutable objects.

Q).Which is the base class for all classes ?
A).
java.lang.Object.

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP