How to Remove key value pairs or Entries from HashMap in Java 8

In the last article, I have shown how to remove key/value pairs from a map in Java based upon some conditions e.g. remove all entries where values are greater than 10$. I have told you that you must use the Iterator's remove() method for removing mapping while iteration to avoid ConcurrentModificationException, but that's not required anymore in Java 8. From JDK 8 onwards, you can selectively remove mapping without iterating over Map. The JDK 8 API has added several new methods to existing interfaces e.g. java.util.Collection, java.util.Map, Comparator etc because the interface can now contain concrete methods in form of static and default methods.

How to enable/disable an element using jQuery and JavaScript? Example

Sometimes we need to enable and disable input elements e.g. text box, radio buttons or checkbox, how can we do it dynamically without loading the page? Well, we can use JavaScript, particularly jQuery to do this. An element can be disabled in HTML by setting disable property to true and enabled again by setting disabled=false. By using jQuery, we can grab the element we want to enable or disable and change this property by using prop() or attr() function, depending upon which version of jQuery you are using. prop() function was added in jQuery 1.6 and its the standard way to deal with properties but attr() function does the same job for jQuery 1.5 and lower version so you can use attr() for the same purpose in jQuery version lower than 1.6.

How to remove key value pair from Map during Iteration - Example tutorial

Suppose you have a Map e.g. HashMap or Hashtable, which contains key value pairs e.g. books and their prices, and you want to remove all books whose prices are greater than 40 USD, How do you that in Java? Many Java programmer, will say that they will iterate over Map and check each entry and then use remove(Object key) or remove(Object key, Object value) methods from java.util.Map to remove any mapping where the value is greater than 40 USD. Though the approach is right, the answer is wrong. Yes, we'll iterate over Map to check each value but we'll not use the two remove() methods from java.util.Map interface because they will throw ConcurrentModficationException, when you call them to remove mapping during iteration. Instead, we'll use the Iterator.remove() method to remove any key value pair, where the value is greater than 40 USD.

10 tips to quickly become productive with new Project/Codebase

One of the main drawback of changing job or changing project it that you lost all subject matter expertise you have learned by working the last couple of years in that project or domain. It doesn't matter whether you are an expert in a programming language, once you change job, you lost your hard earned experience on projects or domain you are working on. When starting a new job or on to a new project you will rarely be working on a complete greenfield environment. Understanding and mastering an unfamiliar code is a difficult process and it can sometimes feel overwhelming due to the amount of new information you need to take on.

Java SE 8 Certification Books - Best of Lot Must Read

If you are preparing for Oracle Certified Associate, Java SE 8 Programmer, also known as Java SE 8 Programmer I or OCAJP8 exam and looking for some good resources e.g. books, study notes, and mock exams then you have come to right place. I have been sharing some of the most useful resources for Java 8 certification aspirants ever since the exam was launched. You can find a lot of this exam and essential resources in this blog. To continue that tradition, I am going to share some of the best books to crack the Java SE certification i.e. OCAJP 8 (1Z0-808)  and OCPJP 8 (1Z0-89). Yes, you need to pass two exams to become Java 8 certified professional. The OCAJP is also a prerequisite for OCPJP exam, which is a professional level exam. Alternatively, if you already hold a Java certification e.g. Java SE 6 or before then you can take one of the upgrade exams e.g. 1Z0-810 to become Java SE 8 certified professional.

Top 10 Java ConcurrentHashMap Interview Questions and Answers

The ConcurrentHashMap class part of concurrent collections added on JDK 1.5 e.g. BlockingQueue, CopyOnWriteArrayList, CopyOnWriteArraySet etc. It is a replacement of synchronized hash-based map implementations e.g. Hashtable and synchronized HashMap. It implements Map and ConcurrentMap (a sub-interface of Map) interface which allows you to store key value pairs. The class is similar to HashMap or Hashtable but it's more scalable and the right fit for concurrent Java application. Unlike Hashtable which achieves its thread-safety by compromising scalability, ConcurrentHashMap uses advanced techniques e.g. dividing the map into segments to remain thread-safe and scalable at the same time.