Category: Java

It’s a fairly common task as a Java developer to convert from a List to an Array or from an Array to a list. In one of my previous post, I discussed about converting Map to List. Like many things in Java, there is often more than one way to accomplish a task. In this […]Continue reading

In applications, you often need to work with a set of constant values. For example, representing a contract status with the “permanent”, “temp”, and “intern” values, or directions with the “north”, “south”, “east”, and “west” values. In Java, you use the enum type (short for enumeration), a special datatype introduced in Java 5 to represent […]Continue reading

Converting a Java Map to a List is a very common task. Map and List are common data structures used in Java. A Map is a collection of key value pairs. While a List is an ordered collection of objects in which duplicate values can be stored. In this post, I will discuss different ways to […]Continue reading

A common requirement while programming in Java is to convert String to int. UI inputs in Web-based HTML, JSP, or Thymeleaf templates are transferred to backend Java applications as strings. It is the application developer’s responsibility to perform any String to int conversions to fulfill business logic, such as calculating discounts, storing age, and so […]Continue reading

Java Architecture for XML Binding (JAXB) is a library that helps to bind XML schemas and Java representations. JAXB provides you with a mechanism to marshal Java objects into XML and the other way around – unmarshal XML into Java objects. XML is an industry standard for defining the contents of your message. XML along […]Continue reading

One common requirement in Java application is to iterate through the elements of a collection. Prior to Java 8, the three most common ways to iterate through a collection are by using the while loop, for loop, and enhanced for loop. As the Java Collection interface extends Iterable, you can also use the hasNext() and […]Continue reading

Prior to Jackson 1.2, the only way to serialize or deserialize JSON using Jackson was by using one of the following two methods: Now imagine you want to serialize or deserialize a 3rd party POJO which you don’t have access to its source code. What would you do? Also, you might want your code clean […]Continue reading

JSON has become the most preferred way of transmitting data across network connections. JSON being easily readable by machines is one of the many reasons for JSON’s popularity. However, JSON unless formatted well, is not easily readable by a human. Pretty printing a JSON is one common operation to improve the readability of the JSON. […]Continue reading

While developing applications, we often need to generate random numbers. Java provides support to generate random numbers primarily through the java.lang.Math and java.util.Random classes. Java also has the ability to generate secure random with java.security.SecureRandom, and random numbers isolated to the current thread with java.util.concurrent.ThreadLocalRandom. You can use the java.util.Random class to generate random numbers of different […]Continue reading

Jackson is a Java library for processing JSON data, enabling customization of serialization and deserialization through various annotations. These annotations, categorized as General, Serialization, Deserialization, and Polymorphic Type, provide developers control over JSON integration with Java objects. Key annotations like @JsonProperty, @JsonIgnore, and @JsonCreator facilitate precise data handling.