Java introduced annotations upon their Java 1.5 release. Since then, annotations have shaped the way we design our applications. In this article, we’ll talk about a set of predefined annotation types in the Java SE API. Some annotation types are used by the Java compiler and some apply to other annotations. What Is Annotation? Annotations are Java types that are preceded by an @ symbol. Java has had annotations ever since the 1.5 release. Since then, they’ve shaped the way we’ve designed our applications. Spring and Hibernate are great examples of frameworks that rely heavily on annotations to enable various design techniques. Basically, an annotation assigns extra metadata to the…
-
-
Different ways to traverse a Map in Java
In this quick article, we’ll have a look at the different ways of iterating through the entries of a Map in Java. Simply put, we can extract the contents of a Map using keySet(), valueSet() or entrySet(). Since those are all sets, similar iteration principles apply to all of them. The Map.entrySet API returns a collection-view of the map, whose elements are from the Map class. The only way to obtain a reference to a single map entry is from the iterator of this collection view. The entry.getKey() returns the key and entry.getValue() returns the corresponding value. Let’s have a look at a few of these. We will use following…