Menu
Topics Index
...
`

Iterator and synchronized blocks


If you need explanation Read this topic

If you need Answer Take test on this topic

Iterator and synchronized blocks
Which of the following is incorrect?

X: Iterator is an interface which is used to step through the elements of a Collection.
Y: Synchronized blocks place locks for longer periods than synchronized methods.
A. X only
B. Y only
C. Both are correct
D. Both are incorrect
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ANS IS C

Iterator is interface to step through the elements of a collection.

And Synchronized blocks place locks for longer periods than synchronized methods.

Posted by Mânïshå Mùlchåndânï    2015-03-17 16:46:40


Answer is A...

Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.

Synchronized block generally reduce scope of lock compared to Synchronized method.
For performance reasons,its always better to lock only critical section of the code.
Take for eg:Singleton Design Pattern  where instead of locking whole getInstance() method we only lock critical section of code which is used to create Singleton instance.So,Synchronized blocks place lock for lesser time  compared to synchronized methods.

Posted by Shashanka Mogaliraju    2015-03-17 17:49:27


This dose is now closed and the winners are Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-03-20 06:47:22


© meritcampus 2019

All Rights Reserved.

Open In App