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.

How to convert a lambda expression to method reference in Java 8?

If you have been coding in Java 8 then you know that using method reference in place of lambda expression makes your code more readable, hence it is advised to replace lambda expression with method reference wherever possible, But, the big question is, how do you find whether you can replace a lambda with method reference? Yes, it's not that easy, especially if you have been using Java 8 only for a couple of months and struggling to get the functional programming concepts and idioms sorted in your head. Anyway, the simple rule to replace lambda expression with method reference is built on common sense, which you will learn in this article.

Top 5 Books to Learn Groovy for Java Developers - Best Of Lot, Must Read

Groovy is a programming language which is specially created for Java developers with a view to being a fast paced, scripting companion to Java. It aims to increase the productivity of Java developer by simplifying Java code by removing unnecessary boilerplate. Groovy not only present a succinct and easy to read syntax but also provide a much more elegant and convenient API than Java for common stuff. For example, a Groovy file can do in 50 lines what a Java source code do in 500 lines. You can declare an array as [] and map as [: ] which really make code full of data without much syntax. Because of this property, Groovy is heavily used in unit testing of Java application using a framework like Spock is built on Groovy.