We visit so many websites each day, there is a lot that happens under the hood just for us to reach the website and get a response.
So let’s say we get on to our browser and type ‘www.example.com’, this could be http://www.google.com, http://www.facebook.com or any of our favorite website. Computers as we know are identified through numbers of the form ‘184.108.40.206’ (IPv4), which are called IP (Internet Protocol) addresses. So ‘www.example.com’ needs to be translated to an address of the form ‘220.127.116.11’ i.e. the address of the web server hosting the website (or webpage). The Domain Name System (DNS), translates the address http://www.example.com to 18.104.22.168 (Refer to my blog on DNS for more information about DNS)
Once the DNS translates the request and sends it back to the browser, the browser send a request to the server located at 22.214.171.124; The server sends the response back in HTML or some programming/ scripting/ markup language that can be interpreted on the screen as response which is then rendered to us as a result.
While, the whole process looks overwhelming, all of this happens in a time faster than a blink of an human eye 🙂
Iterators is a very powerful programming construct. As the name implies, an iterate lets you iterate i.e. run over a list. The iterator can be used to perform various functions on the list.
However, when one thread is iterating over the list, if another thread tries to concurrently modify the underlying list, it results in ConcurrentModificationException. The following code snippets showcases the concept of ConcurrentModificationException.
If we try to add an element to the list while the list is being iterated, it can result in ConucurrentModificationException. There is an integer variable called ‘modCount’ which keeps track of the number of times the list size has been changed. This modCount is used in every next() call.
The ConcurrentModificationException can be avoided by locking the list.
Similarly, the for-each loops also use the Iterator in the background to iterate through the entire collection/ list. Since the for-each loop hides the iterator, it cannot be used to remove/ replace the items belonging to the list/ collection. Trying to remove/ replace the list using for-each loop also creates a ConcurrentModificationException.
Thanks — R