🚀 Day 7 of Learning Spring Boot — and today was all about writing BETTER code, not just working code. Built two real features today: ✅ Get Product by ID ✅ Search Products by keyword But the biggest lesson wasn't about features — it was about HOW you write them. 🔴 I used to write this: product = service.getProductById(id).get(); if(product != null) { ... } Looks fine, right? WRONG. If the product doesn't exist, .get() throws a NoSuchElementException and the null check never even runs. It's literally dead code. 😅 🟢 The correct way using Optional: service.getProductById(id) .map(p -> ResponseEntity.ok(p)) .orElseGet(() -> ResponseEntity.notFound().build()); Clean. Safe. No crashes. This is how pros use Optional. 🔑 Golden Rule I learned today: NEVER call .get() directly on an Optional. Always use .map(), .orElse(), or .orElseGet() --- Also built a Search API that matches keyword across name, brand, description & category — all case-insensitive using JPQL LIKE queries. 🔍 And learned a subtle but important Spring MVC rule: 👉 Always define specific routes like /products/search BEFORE dynamic ones like /products/{id} — otherwise Spring treats "search" as an ID. 🤦 Github Repo : https://lnkd.in/g5aeACUU Small mistakes, big lessons. That's what Day 7 looked like. 💪 #SpringBoot #Java #100DaysOfCode #LearningInPublic #BackendDevelopment #JavaDeveloper #SpringFramework
More Relevant Posts
-
Sometimes, going back to basics teaches you more than learning something new. Today, I revisited spring-boot-starter-web and refreshed my understanding of REST APIs and the core annotations that make everything work behind the scenes. It’s interesting how these small annotations do so much heavy lifting. @RestController makes your class ready to handle web requests. @RequestMapping sets the base path. @GetMapping, @PostMapping, @PutMapping, @DeleteMapping handle different HTTP methods. @PathVariable and @RequestParam help capture inputs cleanly. @RequestBody makes handling JSON feel effortless. At one point, it almost feels like you’re just writing a few annotations and Spring Boot is doing the real job. Revisiting these fundamentals reminded me that strong basics make everything else easier, whether it’s building APIs or learning advanced concepts later on. If you’re ever feeling stuck, going back and refining the basics might be exactly what you need. 👍 #SpringBoot #RESTAPI #Java #BackendDevelopment #LearningJourney
To view or add a comment, sign in
-
-
Continuing my Spring Boot learning series, I want to go beyond how exception handling is implemented and focus on why it actually matters in real-world systems. ⚠️ The real problem I faced In one of my projects, I had implemented exception handling—but not in a well-structured, centralized way. At one point, a failure occurred in a service layer due to an unexpected runtime exception. What followed wasn’t just an error—it exposed deeper issues in my design: - The API returned inconsistent and sometimes empty responses - There was no clear mapping to HTTP status codes - Logs didn’t provide enough context to trace the root cause - Debugging required jumping across multiple layers of the application The issue itself wasn’t complex—but identifying it took significantly longer than fixing it. 🔍 What this revealed The problem wasn’t the exception—it was the lack of a consistent strategy to handle failures. Without centralized exception handling: - Each layer behaves differently under failure - Errors lose context as they propagate - Observability becomes weak - Small bugs turn into time-consuming debugging sessions ✅ What I changed I moved to a centralized exception handling approach using @RestControllerAdvice, along with: - Standardized error response structure - Clear HTTP status code mapping - Proper logging at a single point - Custom exceptions for domain-specific scenarios 🚀 Impact after fixing it - Faster debugging due to better traceability - Consistent API responses across all endpoints - Cleaner controller and service layers - Improved reliability and maintainability 💡 Key takeaway Exception handling is not just about preventing crashes—it’s about making failures observable, predictable, and manageable. In real systems, the difference between a good and bad implementation is not whether exceptions are handled—but how clearly and consistently failures are communicated and traced. Next, I’m planning to explore Caching in Spring Boot. #SpringBoot #Java #BackendDevelopment #ExceptionHandling #SystemDesign #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
I containerized my entire ZenDSA stack. Here is what Docker taught me that no tutorial mentioned. Tutorials make it look simple. Write a Dockerfile. Run docker build. Image appears. Ship it. Then you actually do it on a real project and realize the tutorial skipped the part that matters. Here are 4 things I learned the hard way: 1. Layer caching is real and order matters. If you copy your source code before installing dependencies, every single code change busts the cache and reinstalls everything from scratch. Every build. Took me longer than I want to admit to figure out why my builds were slow. Fix: copy your dependency files first. Install. Then copy source. Cache only breaks when dependencies change. 2. Your image is probably 4x larger than it needs to be. I had node_modules, .git, local configs, and test files all baked into my first image. My .dockerignore was empty. Add a .dockerignore before you do anything else. Treat it like .gitignore. Your image size will shock you before and after. 3. Multi-stage builds exist and you should use them. Build stage compiles everything. Production stage copies only what runs. Dev dependencies stay out. The image that hits your container registry is clean. My ZenDSA production image went from bloated to lean once I split the stages properly. 4. Health checks are not optional if you are running on Kubernetes. Without a health check, Kubernetes has no idea if your container actually started correctly. It just assumes it did. Wire a health check into your Dockerfile and point your readiness probe at the same endpoint. Now K8s routes traffic only after your app is actually ready, not just running. None of this is in the hello world tutorial. All of it matters the moment you deploy something real. ZenDSA is live. 37 users. Every one of them hits a containerized Spring Boot backend I built and ship myself. That is what makes the learning stick. #Docker #Kubernetes #SoftwareEngineering #DevOps #Java #BuildInPublic
To view or add a comment, sign in
-
📚 New Learning in Spring Boot 🚀 Lately, I’ve been diving deeper into Spring Boot, and one concept that really stood out is how Auto-Configuration works internally. --- 🔍 What I learned: 👉 Spring Boot uses @EnableAutoConfiguration to automatically configure beans based on: Classpath dependencies Existing configurations Application properties 👉 Behind the scenes, it reads from: META-INF/spring.factories (or newer auto-config mechanisms) 👉 It follows this logic: If a dependency is present → configure related beans If already defined → don’t override If conditions match → activate configuration --- ⚙️ Why this is powerful: ✅ Eliminates boilerplate configuration ✅ Makes applications production-ready faster ✅ Encourages clean and modular design --- 💡 My Key Takeaway: Understanding “how things work internally” gives much more control than just using annotations blindly. --- 🚀 Next on my learning path: Spring Boot Starter internals Custom auto-configuration Spring Security deep dive --- If you're learning Spring Boot, don’t just use it — understand it. 👉 What concept in Spring Boot confused you the most initially? #SpringBoot #Java #BackendDevelopment #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
When I started learning Spring Boot, I noticed two ways to return data from a controller. Return the object directly. Or wrap it in a ResponseEntity. At first, returning the object directly seemed simpler. Less code. Fewer things to think about. But the more I learned it, the more I understood why ResponseEntity is the right default. When you return a raw object, you are letting Spring decide the status code, the headers, and how the response is shaped. Most of the time it guesses correctly. But an API that works because of guessing is an API waiting to surprise you. ResponseEntity puts you in control of three things at once. The status code, the headers, and the body. All in one place. All explicit. The caller knows exactly what to expect, and you know exactly what you are sending. It also makes your API honest. A method that returns ResponseEntity is saying clearly: I processed your request and I have nothing to give back. A method that returns ResponseEntity is saying: here is the resource you asked for. The contract is visible in the code itself. I have consumed a lot of APIs that didn't make this contract clear. You would get a 200 with an empty body and no idea whether that meant success, not found, or something in between. ResponseEntity is a small habit that makes a meaningful difference. #SpringBoot #Java #BackendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Excited to share my learning journey! I’ve published my first blog on: 👉 How to Build REST API using Spring Boot While learning, I realized that building small projects helps in understanding concepts much better than just watching tutorials. 🔗 Read here: https://lnkd.in/gg8hvBwG I will be sharing more blogs on Java Full Stack Development. #Java #SpringBoot #FullStackDeveloper #LearningJourney #React
To view or add a comment, sign in
-
🚀 Day 12 of my Spring Framework journey: Mastering Stereotype Annotations & Externalized Configuration! 💻 As I dive deeper into Spring, I'm realizing how much it simplifies life for developers by automating the heavy lifting. Today was all about moving away from manual bean registration and embracing a more automated, clean approach. Here are my key takeaways from today's session: 1️⃣ The Power of Stereotype Annotations 🏗️ Instead of defining every bean manually, we can use specialized annotations to let Spring’s component scanning automatically detect and register them. @Component: The base annotation for any generic Spring-managed component. @Service: Specifically for your business logic layer. @Repository: The go-to for data access (DAO) and persistence logic; it even helps with data access exceptions. @Controller: Specialized for the web/presentation layer in Spring MVC. @Configuration: Used for classes that define bean methods via Java code. Why use them? They make your code more readable and maintainable while leveraging the full power of Spring's Dependency Injection. 2️⃣ Dynamic Apps with .properties Files ⚙️ Hardcoding values like database URLs or API keys is a thing of the past. Today, I learned how to externalize configuration so we can change application behavior without recompiling the code: Externalize: Store key-value pairs in a .properties file. Load: Use @PropertySource to point Spring to your configuration file. Inject: Use the @Value("${key}") annotation to pull those values directly into your Java fields. Environment: You can also use the Environment object to fetch properties programmatically. It’s amazing to see how these tools work together to build robust, production-ready applications. Onward to Day 13! 🚀 What’s one Spring feature you can't live without? Let's discuss in the comments! 👇 #SpringFramework #JavaDevelopment #LearningJourney #SoftwareEngineering #BackendDevelopment #SpringBoot #CodingLife #WebDevelopment #StereotypeAnnotations #JavaProperties #TechLearning #JavaProgrammer #JuniorDeveloper
To view or add a comment, sign in
-
Everyone says Spring Boot is easy… But no one talks about why it feels hard in the beginning 👀 When I started, it honestly felt like magic: 👉 APIs working 👉 Dependencies injected 👉 Configurations handled automatically And I kept wondering… “What is actually happening behind the scenes?” ⸻ Then things started clicking 💡 Spring Boot isn’t magic. It’s just: ✔ Auto-configuration making smart defaults ✔ Dependency Injection managing your objects ✔ Annotations defining structure clearly ⸻ 🚀 The real shift for me: I stopped asking ❌ “Which annotation should I use?” And started asking ✅ “What problem am I trying to solve?” ⸻ Because in real projects: 👉 @RestController → exposes your logic 👉 @Service → holds business logic 👉 @Repository → talks to DB It’s not random… it’s structured thinking ⸻ 💡 Biggest realization: Spring Boot doesn’t make things simple… It makes complex systems manageable ⸻ If you’re learning backend, don’t rush Spring Boot. Take time to understand: • How beans are created • How dependency injection works • What auto-configuration actually does That’s where the real learning is. ⸻ Curious — what confused you the most when you started Spring Boot? 👇 #SpringBoot #Java #BackendDevelopment #Microservices #LearningInPublic #Tech
To view or add a comment, sign in
-
I practice Java fundamentals and theory every day, while also building a Spring Boot project to strengthen my practical skills as I work toward a Java developer role. I felt the need for a bit of a refresh...while browsing job listings, I noticed that JavaScript is often in demand as well, so I decided to start learning it 🥳on Boot.dev and I really enjoy its RPG-style learning approach! It’s engaging and gives me a strong boost in motivation 🚀 🤖 If you want to learning something new, I recommend giving it a try: https://lnkd.in/dKNw8NR2 #JavaScript #Learning #JuniorDeveloper
To view or add a comment, sign in
-
🚀 My Spring Boot Learning Journey with Vipul Tyagi's YouTube playlist. 🧑💻 Over the past 2 weeks, I’ve been diving into Spring Boot, and I wanted to share what truly worked for me. I followed the amazing content from Engineering Digest, created by Vipul Tyagi. Specifically, this playlist 👉 Spring Boot Mastery: From Basics to Advanced 💡 Why this stood out: Covers fundamentals → advanced topics in a structured way Clear explanations with practical examples Focus on real-world understanding, not just theory 🛠️ What I did differently: Instead of just watching, I built a code-along project alongside the playlist — which made a huge difference in retention and confidence. 📂 Here’s the project I created: 👉 https://lnkd.in/dhcgxGtG It helped me: ✅ Understand core Spring Boot concepts deeply. ✅ Get hands-on with REST APIs, Security, Architecture, and best practices. ✅ Build something tangible while learning. ✅ Deploy the developed code-along project to railway.app 💭 My takeaway: If you're learning Spring Boot, don’t just consume content, build along with it. That’s where real learning happens. 👏 Huge thanks to Vipul Tyagi for creating such valuable content. This course has 47 videos as of now, and it is completely free and, most importantly, far better than many paid courses. If you're starting your Spring Boot journey, I highly recommend checking this out! https://lnkd.in/dkxHk_U3 #SpringBoot #Java #BackendDevelopment #OpenSource #SoftwareDevelopment #Developers #Programming
What is Spring Boot in Hindi | The Whys and Hows of this Java Marvel!
https://www.youtube.com/
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development