@JsonIgnore

@JsonIgnore — a Jackson annotation used to exclude a field or method from JSON serialization or deserialization. 🧩 Purpose Prevents sensitive or unnecessary data from appearing in JSON responses or being read from incoming JSON. Example: public class User { private String username; @JsonIgnore private String password; // getters & setters } public class…

0 Comments

@SpringBootTest

@SpringBootTest — used to load the entire Spring application context for integration testing in Spring Boot. 🧩 Purpose It allows you to test your app as it would run in production — with all beans, configurations, and environment loaded. Example: @SpringBootTest class UserServiceTest { @Autowired private UserService userService; @Test void testCreateUser() { User user…

0 Comments

@PreFilter & @PostFilter

@PreFilter & @PostFilter are Spring Security annotations used to filter collections or arrays before or after a method executes — based on security expressions. 🧩 @PreFilter Filters input collection before the method runs. Example: @PreFilter("filterObject.owner == authentication.name") public void deleteFiles(List<File> files) { // only files owned by current user remain in 'files' files.forEach(fileRepo::delete); }…

0 Comments

Spring Security Context

Spring Security ContextThe SecurityContext in Spring Security holds the authentication and security-related details (like the logged-in user, roles, etc.) for the current thread of execution. It’s stored in a ThreadLocal, so each request has its own context. Example: import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @RestController public class UserController { @GetMapping("/me") public String getCurrentUser() { Authentication auth…

0 Comments

Trimming whitespace from strings

🔹 1️⃣ String.trim() The classic method for removing whitespace from both ends of a string. Syntax: String trimmed = str.trim(); String trimmed = str.trim(); Behavior: Removes leading and trailing whitespace. Whitespace includes:spaces (' '), tabs ('\t'), newlines ('\n'), carriage returns ('\r'). ✅ Example: String s = " Hello World! "; System.out.println(s.trim()); String s =…

0 Comments

Static blocks

🔹 1️⃣ What Is a Static Block? A static block (also called a static initializer) is a block of code inside a class that is executed when the class is loaded into memory. Runs only once, regardless of how many objects you create. Can be used to initialize static variables or perform class-level setup.…

0 Comments

Java, asynchronous methods

In Java, asynchronous methods are methods that start a task and return immediately, allowing the program to continue executing without waiting for the task to finish. This is useful for I/O operations, network calls, or long-running computations. Java provides several ways to implement asynchronous methods. 1️⃣ Using CompletableFuture (Java 8+) The modern and recommended…

0 Comments

list of strings

Sorting a list of strings in Java is straightforward — and you can do it in several ways, depending on whether you want natural order, reverse order, or a custom comparator. Here’s a complete guide 👇 ✅ 1. Sort in Natural (Alphabetical) Order import java.util.*; public class SortStringsExample { public static void main(String[] args)…

0 Comments

volatile keyword

In Java, the volatile keyword is used to indicate that a variable’s value may be changed by multiple threads, and that all threads should always see the most up-to-date value of that variable. It’s a key concept in multithreading and concurrency. 🧠 Definition A volatile variable is one whose reads and writes go directly…

0 Comments

JUnit annotations

In JUnit (Java Unit Testing framework), annotations are special markers (prefixed with @) that tell JUnit how to run and organize your tests. Let’s go over the most important JUnit annotations — for both JUnit 4 and JUnit 5 (Jupiter). 🧪 JUnit 5 (current standard) JUnit 5 annotations come from the package: import org.junit.jupiter.api.*;…

0 Comments

End of content

No more pages to load