What is the difference between HashMap and Map in Java?

Think of Map as a blueprint for different types of maps. You have different implementations of that blueprint, like HashMap (fast, unordered), TreeMap (sorted order), and LinkedHashMap (insertion order maintained).

Using Map<String, Object> map = new HashMap<>(); is like saying, “I just need a map, and right now I’ll use a HashMap, but I might switch to a different type later.”

On the other hand, using HashMap<String, Object> map = new HashMap<>(); is like saying, “I only want this specific type of map, and I don’t plan to change it.”