As developers, we may need to measure the execution time of specific methods to identify their performance and optimize the code. In this article, we will see how to time profile Java method execution. Java’s System library has a method…
In this article, we will see how to load an image from a file path and convert it into a Bitmap or a Drawable. To create a Bitmap we can use the java.awt.Image and javax.swign.ImageIcon for Drawable. These classes provide…
In many applications, it is common to work with time durations represented in seconds. For better user experience, we often need to convert these time durations into a more human-readable format, such as days, hours, minutes, and seconds. In the…
The “java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException” is a common runtime error we may encounter when running applications, particularly in newer Java versions. If you are facing this error then follow this article to know the possible causes of this error and how to…
In this article, we will find the day of the week using the date in Java. From Java 8, the java.time package provides the date and time functionalities. To see the day of the week, we can use the LocalDate…
In this article, we will see how to cache the HTTP response and use the cached response when the user is offline using Retrofit and OkHttp. OkHttp provides built-in support for caching HTTP responses. To enable caching in Retrofit, we…
In this article, we will see how to pretty print a map in Java and make it easier to visualize the key-value pairs. Let us first create an example map to show how to do a pretty print of the…
In this article, we will see how to find if the given substring is present in the entire string or not. Java’s java.util.regex package provides classes such as Pattern and Matcher to perform the substring matching. First, import the required…
In this article, we will see how to generate a random date between two dates in Java. In Java, we can use the java.time.LocalDate to represent a date without a time component and this along with java.time.temporal.ChronoUnit we can calculate…
In this article, we will see how to implement random sleep in Java which helps to avoid synchronization issues and make the behaviour of concurrent programs less predictable. Using the java.util.Random class, we can generate random values and these random…