Coding Problems Cheatsheet

Category Problem Key Concepts/Strategies Detailed Explanation Code Example Arrays & Hashing Contains Duplicate Use a set to track seen numbers Iterate through the array, adding each element to the set; return true if an element is already in the set. Valid Anagram Use a hashmap to count character frequencies Count characters in both strings using hashmaps and compare the counts. Two Sum Use a hashmap to store indices of elements Iterate through the array, for each element, check if the complement (target - element) exists in the hashmap....

July 7, 2024 · 6 min · 1081 words · PandaC

Understanding Usecase Diagram

What is a Use Case Diagram? A use case diagram is a type of drawing that shows how different people (called “actors”) interact with a system (like a software program or website). It’s a way to show what the system does and who uses it. Key Notions (Symbols) in a Use Case Diagram: Actors: Stick Figure: Represents a person or thing that interacts with the system. For example, a student, teacher, or librarian....

June 17, 2024 · 3 min · 458 words · PandaC

Understanding UML Diagrams

Unified Modelling Language (UML) is a standardised way to visualize the design of a system. UML diagrams can be categorized into two main types: Structural Diagrams and Behavioral Diagrams. Understanding these categories helps in effectively modeling both the static and dynamic aspects of a system. Structural Diagrams Structural diagrams represent the static aspects of a system. They show the system’s classes, objects, and relationships. Here are the key types of structural diagrams:...

June 17, 2024 · 3 min · 626 words · PandaC

Consuming REST Services in Spring Boot: RestTemplate, WebClient, and Feign Client

Spring Boot provides several robust options for consuming RESTful web services. In this blog post, we will explore three primary methods: RestTemplate, WebClient, and Feign Client. Each approach offers unique features and benefits suited for different use cases. 1. RestTemplate Description: RestTemplate is a synchronous client for performing HTTP requests. It is simple to use and ideal for applications where synchronous calls are sufficient. Setup and Usage: Add Dependency: To use RestTemplate, add the following dependency to your pom....

June 10, 2024 · 2 min · 411 words · PandaC

Asynchronous processing in a Spring Boot REST

Configuring asynchronous processing in a Spring Boot REST application allows you to handle requests without blocking the main thread, improving performance and responsiveness. Here’s a step-by-step guide to enable and configure asynchronous processing in your Spring Boot REST application: 1. Enable Async Support First, enable asynchronous processing by adding the @EnableAsync annotation to your Spring Boot application class or any other configuration class. import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication @EnableAsync public class AsyncApplication { public static void main(String[] args) { SpringApplication....

June 10, 2024 · 4 min · 789 words · PandaC

Internationalization (i18n) in Spring Boot with Thymeleaf

Internationalization (i18n) in Spring Boot with Thymeleaf allows you to create web applications that can support multiple languages. This involves setting up message resource files for different languages and configuring your application to use them. Here’s a step-by-step guide to set up i18n in a Spring Boot application using Thymeleaf: Step 1: Add Dependencies Ensure you have the necessary dependencies in your pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> Step 2: Create Message Resource Files Create message resource files for each language you want to support....

June 10, 2024 · 3 min · 527 words · PandaC

Spring Boot 3 Rest: Error Handling

Handling exceptions gracefully in a Spring Boot 3 REST application is crucial for providing clear and consistent error responses to the clients. In this section, we’ll explore how to handle exceptions for REST controllers using @ControllerAdvice and @ExceptionHandler annotations, and customize error responses. Setting Up the Project Ensure you have the necessary dependencies in your pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> Step 1: Create a Custom Exception Define a custom exception that can be thrown by your REST controllers:...

June 10, 2024 · 5 min · 1021 words · PandaC

Spring Boot 3 with Thymeleaf: Error Handling

In modern web applications, providing clear and user-friendly error messages is crucial for a good user experience. In this blog post, we’ll explore how to customize error handling in a Spring Boot 3 application using Thymeleaf. We’ll look at how to create custom error attributes, define a global error controller, and design a custom error page with Thymeleaf. Setting Up the Project First, ensure your Spring Boot 3 project is set up with the necessary dependencies....

June 10, 2024 · 5 min · 905 words · PandaC

Using Thymeleaf with Spring Boot

Thymeleaf is a modern server-side Java template engine for web and standalone environments. It is particularly well-suited for Spring Boot applications, offering a natural way to create dynamic web pages. In this blog post, we’ll explore how to integrate Thymeleaf with Spring Boot, create dynamic templates, and use Thymeleaf’s powerful features to build a simple web application. Setting Up Thymeleaf with Spring Boot Step 1: Create a Spring Boot Project Start by creating a new Spring Boot project using Spring Initializr or your preferred method....

June 9, 2024 · 4 min · 746 words · PandaC

Spring Boot Devtools to Speed Up Development

Spring Boot Devtools is a powerful tool that significantly improves the development experience by providing features like automatic restarts, live reload, and configurations that are optimized for development. In this blog post, we’ll explore how to set up and use Spring Boot Devtools to speed up your development workflow. Why Use Spring Boot Devtools? Spring Boot Devtools enhances the development process in several ways: Automatic Restarts: Automatically restarts your application whenever files on the classpath change, saving you the hassle of manually restarting the server....

June 9, 2024 · 4 min · 661 words · PandaC