java

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

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