What is the difference between Iterator and Enumeration? What is the difference between exception and error?What is the difference between final, finally and finalized? What is Synchronisation in threadsWhat is the difference between wait(), join(), sleep(), notify() & notifyall() methods? When should i used notify() and notifyall() methods on threads? thank u sir/mam

Showing Answers 1 - 9 of 9 Answers

praveen kumar IBM

  • Sep 7th, 2006
 

By using Iterator we can retrive the values one by one.  but by using ennumerator we can retrive more than one value.  by using iterator we can remove the value but in ennumerator we can't.

mukesh kumar

  • Sep 8th, 2006
 

thanks

  Was this answer useful?  Yes

Surbhi

  • Sep 9th, 2006
 

The Except ion class is refer to condit ions that user programs can reasonably deal with.These are usually the result of some flaws in the user program code. Example ofExcept ions are the division by zero error and the array out -of-bounds error.The Error class, on the other hand, is used by the Java run- t ime system to handle errorsoccurring in the run- t ime environment . These are generally beyond the cont rol of userprograms since these are caused by the run- t ime environment . Examples include out ofmemory errors and hard disk crash.

  Was this answer useful?  Yes

What is the difference between Iterator and Enumeration?

Both are used go through the collection objects.Enumeration is read only.we can't change the object or value  in the collection.we have only forward facility.

we have two type of Iterators those are Itrator and ListIterator Using of the iterator we can remove the objects form the collection. Using of the listIterator we can go forward  and privious in the collection objects.

What is the difference between exception and error?

Exception is an obnormal condition raised while executing the program.

Error is a condition that don't occur under normal conditions.Ex run out of memory,stack over flow.

What is the difference between final, finally and finalized?

Final: We can apply the final keyword to variables,methods and classes .If a variable is declared as final we can't change the values. if method is declared as final we can't override.if class is declared as final we can't subclassed.

Finally:whether an exception is raised or not finally block must execute.

Finalized:All objects have finalize method it is inherited from Object class.It is used to release system resources.Giving a chance to object free their resources before destorying.It is called prior to garbage collector.

What is the difference between wait(), join(), sleep(), notify() & notifyall() methods?

Wait(): Blocked until certain conditin occures -notify()

Sleep():Blocked for a specifed time.

suspend():Blocked until further orders -resume()

notify(): it is used to bring waiting thread to runnable state.

notifyall():It is used to bring all waiting thread to runnable state.

join():waiting for thread to finish or die.

  Was this answer useful?  Yes

shreeuw

  • Oct 23rd, 2008
 

Enumeration is twice as fast as Iterator and uses very less memory. Enumeration is very basic and fits to basic needs. But Iterator is much safer as compared to Enumeration, b’ coz it always denies other threads to modify the collection object which is being iterated by it. Whenever a second thread tries for that Iterator will throw a ConcurrentModificationException. Iterators that do this are known as fail-fast iterators, as they fail quickly and cleanly.

  Was this answer useful?  Yes

janmaijais

  • Jul 6th, 2009
 

Final keyword use before variable, then this variable behave like cons.
Final use before method then we can't override the method.
Final use before class then we can't inherit this class.
Finally keyword use in thread, its mean exception is occur and caught or exception occur but not caught then finally block executed, mean each and every condition finally block executed.
Finalized is keyword, which is use before garbage collection, release the resources that is occupied by object.

  Was this answer useful?  Yes

Iterator - Interface to iterate over collections

Enumertion - Type of collecton of objects

Exception - Occurs when some logically wrong happens in program. Can be catched
Error - Not in hands of developer or user. Occurs due to JVM failure etc. Cannot be catched.

Final - It is a keyword used with class, method and variable
Finally - It is a block used with try.
Finalize() - It is a method which executes before an object gets garbage collected

Synchronization - It is process to handle mutliple threads so that two threads cannot access the same code at same time

wait() - Waiting for some thread to finish
join() - join the current thread
sleep() - sleeps the thread for a particular time period
notify() - notify a thread for some activity
notifyall() - notify all threads for some activity

You can use notify when some thread is waiting for some operation. Then after that operation you call notify or notifyall based on to notify one or all threads respectively


  Was this answer useful?  Yes

svsrinivas

  • Aug 10th, 2009
 

Error comes at compilation time, Exception comes at run time.


final keyword is used in three ways


final int i=10;


This represents i is constant we can't change the value of i;
If you used in front of method that will tell that method is not allowed for
inheritance;
If you used in front of class it doesn't supports inheritance;


sychronisation is used to protect the method (some code) from multiple users
request.


wait() - to send the thread to waiting state.
join() - to wait for other thread execution.
sleep() - this also to make thread in sleep state.


To resume thread from sleeping state we use the notify(), for all threads we
use notifyall().

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions