![]() |
![]() |
![]() |

![]() |
![]() |
![]() |


![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |

![]() |


![]() |
![]() |
![]() |
|
What is rate limiting per API in spring boot? Rate limiting is an architectural tactic for a server to limit access to an API. It helps to: protect against server overload due to clients that call the server in a short time frame too often. increase the fairness of how clients use server resources.
|
RestClient is becoming the replacement for RestTemplate. And in many cases,
WebClient isn’t really needed and it can be overkill if you're not using a reactive approach.



Filter + Map
List<String>
result =
list.stream()
.filter(s -> s.startsWith("A"))
.map(String::toUpperCase)
.toList();
Frequency Count
String str =
"today is my interview";
Map<Character, Long> map =
str.toLowerCase()
.chars()
.mapToObj(c -> (char) c)
.filter(c -> "aeiou".indexOf(c) >= 0)
.collect(Collectors.groupingBy(
Function.identity(),
Collectors.counting()
));
System.out.println(map);
groupingBy
Map<String,
List<Employee>> deptMap =
employees.stream()
.collect(Collectors.groupingBy(
Employee::getDepartment
));
Parallel Stream
list.parallelStream()
.forEach(System.out::println);
Thread Pool
Fixed Thread Pool
ExecutorService
executor =
Executors.newFixedThreadPool(5);
Cached Thread Pool
ExecutorService
executor =
Executors.newCachedThreadPool();
Scheduled Thread Pool
ScheduledExecutorService
scheduler =
Executors.newScheduledThreadPool(2);
scheduler.schedule(
() -> System.out.println("Executed"),
5,
TimeUnit.SECONDS
);
CompletableFuture
Async Processing
CompletableFuture<String>
future =
CompletableFuture.supplyAsync(() -> {
return "Hello";
});
System.out.println(future.get());
thenApply
CompletableFuture<String>
future =
CompletableFuture.supplyAsync(() -> "java")
.thenApply(String::toUpperCase);
System.out.println(future.get());
Combine Multiple APIs
CompletableFuture<String>
user =
CompletableFuture.supplyAsync(() -> "User");
CompletableFuture<String> account =
CompletableFuture.supplyAsync(() -> "Account");
CompletableFuture<String> result =
user.thenCombine(account,
(u, a) -> u + " " + a);
System.out.println(result.get());
Singleton
Eager Singleton
public class
Singleton {
private static final Singleton INSTANCE =
new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return INSTANCE;
}
}
Lazy Singleton
public class
Singleton {
private static Singleton instance;
private Singleton() {}
public static synchronized Singleton getInstance() {
if(instance == null) {
instance = new Singleton();
}
return instance;
}
}
Double Checked Locking
public class
Singleton {
private static volatile Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if(instance == null) {
synchronized (Singleton.class) {
if(instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
REST Controller
@RestController
@RequestMapping("/users")
public class UserController {
@GetMapping("/{id}")
public ResponseEntity<User> getUser(
@PathVariable Long id) {
return ResponseEntity.ok(
new User(id, "John")
);
}
}
POST API
@PostMapping
public ResponseEntity<User> createUser(
@RequestBody User user) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(user);
}
Validation
public class
UserRequest {
@NotBlank
private String name;
@Email
private String email;
}
Global Exception Handling
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handle(
Exception ex) {
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ex.getMessage());
}
}
REST API Best Practices
- Stateless
- Proper HTTP methods
- Pagination
- Validation
- DTO pattern
- Centralized exception handling
- Correlation IDs
- API versioning
- Swagger/OpenAPI
MOST IMPORTANT INTERVIEW TOPICS TO MASTER
Java Internals
· JVM memory
· GC
· HashMap internals
· synchronization
· thread safety
Coding
· streams
· collections
· concurrency
· singleton
· LRU cache
Enterprise
· REST APIs
· exception handling
· transaction management
· microservices
What is the output of Optional.of(null)?

What are the principles of microservices architecture?
microservices is basically breaking down a big application into lots of smaller, independent services that each do one thing well. The core principles are that each service is loosely coupled, meaning they don't depend heavily on each other, and they communicate through well-defined APIs. Each service can be developed, deployed, and scaled independently, which gives you a lot of flexibility. They're also organized around business capabilities rather than technical layers,