Skip to main content

Posts

Showing posts from April, 2025

Retry module - Resilience4j

as we discussed about circuit breaker module from resilience4j earlier, let's see what Retry module actually offers What is Retry in Resilience4j? this module offers ways of handling failure transaction by automatically retrying those transactions as per properties we configure. let's check how it works in this article. below code shows, how we can add retry annotation to our feign client Note: There is no need to add a fallbackMethod in the @Retry annotation if it is already defined in @CircuitBreaker . @GetMapping("/users/{userId}/albums") @Retry(name="album-service") @CircuitBreaker(name = "album-service", fallbackMethod = "getAlbumsFallbackMethod") public List<AlbumResponseModel> getAlbums(@PathVariable String userId); default List<AlbumResponseModel> getAlbumsFallbackMethod(String userId, Throwable exception) { System.out.println("user id" + userId); System.out.println("exc...

Mastering Java Streams: Smart Ways to Handle Strings Like a Pro

Working with strings is a daily task for Java developers. But if you're still stuck in loops and if-else blocks, it’s time to level up! ๐Ÿ’ช Java Streams offer a clean, expressive, and functional way to process strings—whether you're transforming, filtering, or analyzing them. In this blog, we’ll explore: ๐Ÿ› ️ Different ways to use streams on strings in Java ๐Ÿ’ผ Popular interview questions involving Java strings and streams Whether you're a beginner or an experienced developer preparing for interviews, this guide has you covered. ✨ Section 1: Different Approaches to Use Streams on Strings in Java Let’s look at how to apply Java Streams on strings using various real-world examples. 1. Convert a String to a List of Characters List<Character> characters = str.chars() .mapToObj(c -> (char) c) .collect(Collectors.toList()); ๐Ÿงพ Explanation: str.chars() returns an IntStream of character codes. .mapToObj(c -> (char) c) casts each int...

Java Streams Interview Questions and Solutions

 Java Streams are a powerful feature introduced in Java 8 that enable functional-style operations on collections. Recently, I was asked a few Java Streams-related questions in an interview, and I would like to share my solutions along with explanations and better alternatives where applicable. Interview Questions and Solutions 1. Get Employees Whose Salary is Greater Than 6000 and Name Starts With 'S' Question: Given a list of employees, filter out employees who earn more than 6000 and whose names start with the letter 'S' . Solution: List<Employee> empStartsWithS = employees.stream() .filter(e -> e.getSalary() > 6000.0 && e.getName().toLowerCase().startsWith("s")) .collect(Collectors.toList()); System.out.println(empStartsWithS); Explanation: filter() is used to apply the condition: salary > 6000 and name starts with 's' . collect(Collectors.toList()) collects the filtered eleme...

1ntr0duct10n

 Hey folks, welcome to sem1c010n..! If you're looking for perfect coding content, you're in the right place...! We keep you excited every time with fresh content — dive in and get codified! Stay tuned... keep coding ๐Ÿš€