Java

Frequency of each word in a given string

This a quick tutorial for finding the frequency of each word in given string using java. This is a frequently asked question in interviews. They might ask to write the code in Java or Java 8. Lets see how to write it in Java 8 way first as Java 8 is trending in current market.   Try the above codes and see the result. Thanks for reading!!!!

0
Read More

Predicate in Java 8 and how it works

5 mins might be useful if you spend on this page. This is a quick hands on one of the cool feature of java 8. It is helps to reduce the lot of boiler plate code and focused many runtime implementation using @FunctionalInterface. @FunctionalInterface -> A interface which has only one abstract method. It can contain any number of default and static method. We will be talking about Predicate (shown below). @FunctionalInterface interface Predicate<T> Predicate has one abstract method ->…

0
Read More

java.lang.UnsupportedOperationException while adding element to List created from Arrays.asList()

The arraylist which is created using below line of code is immutable. The reason behind is the list still backed/aided by the array and we all know pretty well that the size of the array cannot be changed. The Arrays.asList returns the arraylist which is the inner class with the name as arraylist. This list does not have methods that performs any modification to the arraylist add, remove etc. It is an inner class which extends abstract class AbstractList but not…

0
Read More

How to configure and set expire in Redis cache using Spring Boot?

Introduction We have different cache techniques in this software industry. We will have a small talk about Redis Cache. We use cache service to improve the API response means we save the response in the cache for a duration and response is sent back from cache instead of real service/databases. Reduces the backend API calls / Database calls. Reduces loads on the blackened server. Let’s Try: Let’s Start on Redis container part.  We can run a Redis docker container in…

0
Read More

Try with Resources in Java

Introduction: The try-with-resources statement introduces in Java 7 is a try statement that declares one or more resources.A resource is an object that must be closed after the program is finished with it.The try-with-resources statement ensures that each resource is closed at the end of the statement.Any object that implements java.lang.AutoCloseable interface, which includes all objects which implement java.io.Closeable,can be used as a resource. see the below sample code:- Note: More than two resources can be added separated by a…

0
Read More

Restart a thread Using UncaughtExceptionHandler

There is always a scenario in a development process where a piece of any code/line (e.g.,business logic) throws some unchecked/runtime exception which is not possible to handle as we are not sure about the user input. In that case the thread responsible for executing that piece of code dies off and the assigned task remain unfinished. Due to this the output may not be consistent and the reuslt can be pretty random. Let us take the below example, To overcome…

0
Read More
serialization-image

Serialization in java

What is Serialization in Java? Object Serialization in Java is a process used to convert Object into a binary format which can be persisted into disk or sent over network to any other running Java virtual machine; the reverse process of creating object from binary stream is called deserialization in Java. Java provides Serialization API for serializing and deserializing object which includes java.io.Serializable, java.io.Externalizable ObjectInputStream and ObjectOutputStream etc. Java programmers are free to use default Serialization mechanism which Java uses…

0
Read More