Head First Series : Design Patterns

One of the Best Books to understand Design Patterns, the third most important thing to learn after Data Structures and Algorithms for a Software Developer.

Order your copy today by clicking on the image below.

Completable Futures… the future of Parallel processing in Java

During my recent interview, i was asked to design the flow of 5 parallel calls and returning the first response that i will get from any of those 5 different calls. I was aware that for parallel calls i will have to somehow use a Future. But the requirement of getting the first response from any of them and returning it as the answer confused me.

Future has been around since a long time now. Even Completable Future has been present since Java 8.

We need to use the anyOf() method to return the first response from the list of futures.

I am sharing my findings below. If you have a better solution please provide your inputs in the comments sections.

/**
An Example where we are calling 4 different Calls and returning the first response that we receive from any of these calls.
Please note this is not a working example, this is a sample code to give you a high level idea.
*/
//Here we create 4 Sample Futures
CompletableFuture<SearchResponse> aggregatorFuture1 = new CompletableFuture<>().supplyAsync(aggregator1.getSearchResult(request));
CompletableFuture<SearchResponse> aggregatorFuture2 = new CompletableFuture<>().supplyAsync(aggregator2.getSearchResult(request));
CompletableFuture<SearchResponse> aggregatorFuture3 = new CompletableFuture<>().supplyAsync(aggregator3.getSearchResult(request));
CompletableFuture<SearchResponse> aggregatorFuture4 = new CompletableFuture<>().supplyAsync(aggregator4.getSearchResult(request));
//Create the List of Above 4 Futures
List<CompletableFuture<String>> aggregatorFuturesList = Arrays.asList(aggregatorFuture1,aggregatorFuture2, aggregatorFuture3, aggregatorFuture4);
//Creating a new Future and using the anyOf() method which uses the list of futures
// that will Returing the first response from any of the 4 futures above
SearchResponse response = CompletableFuture.anyOf(aggregatorFuturesList)
.thenApply(r -> {
if (r instanceof SearchResponse) {
return (SearchResponse) r; //We need to type cast the response as well.
}
throw new Exception("Response type is not of SearchResponse!");
}).join();

Cracking the Coding Interview…

A Coding Interview is one thing that every software developer fears and cracking it definitely not easy.

And the One Book that should be present in every Software Developer’s arsenal is the famous book Cracking the Coding Interview: 189 Programming Questions and Solutions by Gayle Laakmann McDowell

Please note : Keep it under your Pillow before going to sleep to keep the nightmares away 😛

What are Shutdown Hooks in Java

Shutdown Hooks in Java.

Follow  @javareboots on Instagram for your Java doses 💊  and  be ready for any Coding interviews 

#javareboots #javadoseoftheday #coders #programmers #javaprogramming #javaprogrammer #codingislife #interviewtips #interviewprep #java #multithreading

CONCURRENCY vs PARALLELISM in JAVA

CONCURRENCY vs PARALLELISM in JAVA has always been a confusing concept to understand even for experienced developers.
CONCURRENCY vs PARALLELISM is one of my all-time favourite java questions to ask in an interview. And the majority of the answers that you hear will always surprise you.
Its always better to prepare for the answer beforehand instead of surprising your interviewers every time 😛
So what is Concurrency in Java?

IMG_20191107_113448_487.jpg
What is Concurrency in Java?
Then What is Parallelism in Java?

IMG_20191107_113448_488.jpg
What is Parallelism in Java?
Follow  @javareboots on Instagram for your Java doses 💊
and be ready for Coding interviews
#javareboots #javadoseoftheday
#coders #programmers #javaprogramming #javaprogrammer #codingislife #interviewtips #interviewprep #java #multithreading

The SOLID Design Principles in Software Development

The famous SOLID Design Principles

Follow  @javareboots on Instagram for your Java doses 💊  and  be ready for any Coding interviews 

#javareboots #javadoseoftheday #coders #programmers #javaprogramming #javaprogrammer #codingislife #interviewtips #interviewprep #java #multithreading

Does Java – pass by value or pass by reference ?

Are the Parameters in Java , passed by value or passed by reference ?

And the correct answer can surprise you as well ! This is quite confusing to understand at first.

Java – pass by value or pass by reference

Follow  @javareboots on Instagram for your Java doses 💊  and  be ready for any Coding interviews 

#javareboots #javadoseoftheday #coders #programmers #javaprogramming #javaprogrammer #codingislife #interviewtips #interviewprep #java #multithreading