Builder Design Pattern in Java

Builder Design Pattern in Java

The builder pattern, as the name suggest, we can use this pattern to build/construct complex objects. We should use this pattern when we want to construct same type of immutable objects with different sets of attributes. Goal of Builder Design Pattern (https://en.wikipedia.org/wiki/Builder_pattern) The goal of Builder design pattern is to separate the construction of a complex object from...

org.redisson.client.RedisException: Unexpected exception while processing command

org.redisson.client.RedisException: Unexpected exception while processing command

org.redisson.client.RedisException: org.redisson.client.RedisException: Unexpected exception while processing command at jdk.internal.reflect.GeneratedConstructorAccessor358.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:600) at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:678) at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:737) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:661) at jdk.internal.reflect.GeneratedMethodAccessor1318.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) at...

Exception Handling with Method Overriding in Java

Exception Handling with Method Overriding in Java

In our day to day programming we use method overriding widely. Have you ever considered how exception handling rule works in method overriding? Lets see how it works in Java with example.   RULE 1. Super class method does not declare any exception in its method signature. If super class method does not declared any exception in its method...

What is the difference between Error and Exception in Java?

What is the difference between Error and Exception in Java?

Errors and Exceptions are the subclasses of Throwable. However it hold different context for any Java program.   Errors result from failures detected by the Java Virtual Machine, such as OutOfMemoryError, StackOverflowError, etc... Most simple programs do not try to handle errors. For errors programs are not expected to recover. Mostly errors results from lack of resources provided...

BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq

BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq

BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq One weird exception where Google doesn't show whats wrong with our code or process. I faced same exception and I scratched my head all day long to fix this issue and finally I fixed it. I'm using phone based Authentication of Firebase. Step 1: Enable Firebase logging to see behind whats...

How to create immutable class in Java?

How to create immutable class in Java?

Immutable Object Once created its state can not be altered. String is good example of Immutable class in Java which you use in your day-to-day programming. Read: Why String is immutable in Java? Most important benefit of immutable class is, It provides thread safety so you don't have to worry about its value getting changed in multi-threaded environment....

How LinkedHashMap works internally in Java?

How LinkedHashMap works internally in Java?

LinkedHashMap implemented using the HashMap. So before we begin to understand How LinkedHashMap works you should first read How HashMap works internally in Java? We will understand part of code that defers from HashMap and supports LinkedHashMap implementation. LinkedHasMap#Entry Entry class in LinkedHashMap extends Node class of HashMap and contains two more variable before and after to hold...

Popular Map interview questions in Java

Popular Map interview questions in Java

Question: Why Map interface does not extends Collection interface? Answer: Map is (key, value) pair not a collection of one type of values so it does not extends Collection interface. Collection interface accept single object via add(E e) but Map interface requires key, value pair in method put(K key, V value) Question: Does Map accept `null` as key?...

How HashMap works internally in Java?

How HashMap works internally in Java?

HashMap is one of the implementation of java.util.Map interface. We will understand how it internally stores (put) and retrieve (get) values. HashMap uses array known as bucket/table to store (key, value) pair. This is one of the popular question in Java Interviews, lets understand how it works. Instantiation: How to create HashMap object? There are 3 different ways...

What is Abstract class in Java and popular interview questions?

What is Abstract class in Java and popular interview questions?

What is Abstract Class? An abstract class is a class that is incomplete, or to be considered incomplete. You can declare abstract methods for which non abstract subclass has to provide implementation or it'll give compile-time error. "Methods that are declared but not yet implemented." Also you can provide method implementation in abstract class itself. It can be...