Me: I'll just refactor this one method. 3 hours later: I've rewritten the entire service layer, questioned my career, and ordered biryani. Being a dev is a whole personality. 😭
#DevHumor#ProgrammerHumor#JavaDev#DevLife#Relatable
💡Java: When possible, avoid returning mutable internal collections from methods, so that:
1) You don't expose internal state, improving security
2) You can change the implementation without breaking other parts #Java#JavaDev
🚀Spring Cloud: Eureka service discovery. Call services by name, not IP.
✅ Each service registers with Eureka on startup
✅ Eureka tracks healthy instances via heartbeats
#SpringBoot#JavaDev 🧵
💡Java: Avoid magic numbers. In Java, a Magic Number refers to a hard-coded numeric value used in code without any explanation of what it represents. Magic numbers reduce readability and make maintenance harder. #JavaDev#CleanCode
💡Java: VarHandle can be used as a lighter alternative to volatile. It's a strongly typed reference to a variable.
✅ When two threads share a variable, the CPU can reorder and cache writes. One thread updates a value, the other keeps seeing the old one. #JavaDev🧵
💡 Java 14 switch expressions are exhaustive: the compiler verifies that every possible value is handled.
✅ Miss an enum constant and compilation fails
✅ Fix it by covering all enum values or adding a default branch
✅ Safer refactors and fewer hidden bugs
#Java#JavaDev
🚀 Spring Boot: @AutoConfigureMockMvc allows you to test controllers without starting the server. It tells Spring Boot to automatically configure a MockMvc instance in the test context.
#SpringBoot#JavaDev
🚀 Spring Boot: It has built-in support for pagination with Pageable.
✅You should use pagination in your repositories instead of fetching all.
#SpringBoot#JavaDev
🚀Spring Boot: You have the choice of using WebClient over RestTemplate in new apps.
✅ It’s reactive and non-blocking
✅ Based on event-loop instead of thread-per-request
#SpringBoot#JavaDev
🚀Java: Starting from Java 14, you can use records to create short, immutable, data-carrying objects.
✅ They are shorter than ordinary POJOs
✅ They have built-in equals(), hashCode(), toString()
✅ They are immutable by default
#JavaDev#Records
🚀 SpringBoot: You can add global OpenAPI metadata with @OpenAPIDefinition.
✅ It should be put on your main Spring Boot application class, or a dedicated configuration class
#SpringBoot#JavaDev