🌱 Day 4 of My Tech Journey — Understanding @PathVariable & @RequestParam in Spring Boot Today I explored how to send data through a REST API in Spring Boot using path parameters and query parameters. Here’s a simple example: @RestController @RequestMapping("/api") public class UserController { @GetMapping("/user/{id}") public String getUser(@PathVariable int id, @RequestParam(required = false) String name) { return "User ID: " + id + ", Name: " + name; } } 👉 Output: User ID: 10, Name: Harshita 🔑 Takeaway: @PathVariable is used to pass values inside the URL, while @RequestParam is used for query parameters. #SpringBoot #Java #RESTAPI #CodingJourney #BackendDevelopment
Understanding @PathVariable and @RequestParam in Spring Boot
More Relevant Posts
-
🧩 Day 5 of My Tech Journey — Understanding @RequestBody in Spring Boot Today I explored how data is sent from the client to the backend in a POST API using the @RequestBody annotation. Example: @RestController @RequestMapping("/api") public class UserController { @PostMapping("/addUser") public String addUser(@RequestBody User user) { return "User added: " + user.getName(); } } // Sample JSON Input: { "name": "Harshita", "email": "harshita@example.com" } ✅ Takeaway: @RequestBody helps map incoming JSON directly to a Java object, making REST communication clean and efficient. #SpringBoot #JavaDeveloper #RESTAPI #CodingJourney #BackendDevelopment
To view or add a comment, sign in
-
Day 43/100 Problem Statement : Given an array nums, you can perform the following operation any number of times: Select the adjacent pair with the minimum sum in nums. If multiple such pairs exist, choose the leftmost one. Replace the pair with their sum. Return the minimum number of operations needed to make the array non-decreasing. An array is said to be non-decreasing if each element is greater than or equal to its previous element (if it exists). Input: nums = [5,2,3,1] Output: 2 Solution : https://lnkd.in/g3Z6NQxN public int minimumPairRemoval(int[] nums) { int length = nums.length - 1; int count = 0; while(length > 0) { boolean increase = true; int minSum = Integer.MAX_VALUE; int minIndex = -1; for(int i = 0; i < length; i++) { if(nums[i] > nums[i + 1]) increase = false; if(nums[i] + nums[i + 1] < minSum) { minSum = nums[i] + nums[i + 1]; minIndex = i; } } if(increase) break; nums[minIndex] = minSum; for(int i = minIndex + 1; i < length; i++) nums[i] = nums[i + 1]; length--; count++; } return count; } #100DaysDSA #100DaysOfCode #Java #Leetcode #Neetcode #Neetcode250 #TUF
To view or add a comment, sign in
-
Ever called map.get("Key1") on a HashMap and wondered what really happens behind the scenes? I did too, and it’s surprisingly cool. Here’s a quick breakdown of what goes on internally: → First, the key’s hashCode() is calculated to decide *where* the entry should live in memory. → Next, the index is computed (something like hashCode & (arrayLength - 1)). → If multiple keys end up at the same spot (collision), HashMap handles it using a linked list, or even a tree (from Java 8 onward) when things get heavy. → Finally, equals() is used to confirm we’ve got the exact key before returning the value. Important takeaway: if you override hashCode(), always override equals() too, they’re a package deal! Fun fact: a bad hashCode() can make your map sluggish, even with few entries. Have you ever implemented your own custom key class? #Java #HashMap #CodingTips #Developers #100DaysOfCode #LearnWithNayan Credits: https://lnkd.in/dK9deahF
To view or add a comment, sign in
-
-
🔥 Day 97 of my 100 Days of Code Problem: Binary Tree Inorder Traversal (LeetCode #94) Problem Description: Given the root of a binary tree, return the inorder traversal of its nodes’ values. Inorder means visiting nodes in this order: Left -> Node -> Right Java Solution: class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> result = new ArrayList<>(); Stack<TreeNode> stack = new Stack<>(); TreeNode current = root; while (current != null || !stack.isEmpty()) { // Reach the leftmost node while (current != null) { stack.push(current); current = current.left; } // Process node current = stack.pop(); result.add(current.val); // Visit right subtree current = current.right; } return result; } } Time Complexity: O(n) Space Complexity: O(n) (for stack in the worst case) #Day97 #LeetCode #100DaysOfCode #Java #BinaryTree #DFS
To view or add a comment, sign in
-
-
I’ve been learning more about Spring Boot annotations, and I wanted to share some key insights that really helped me understand how each layer works in a Spring application 👇 If you're diving into Spring Boot, here are some of the most essential annotations you should know 👇 ✅ @SpringBootApplication → The main entry point of your Spring Boot application. 🌐 @RestController, @GetMapping → Handle incoming web requests and return responses (like JSON or XML). 💼 @Service, @Repository → Define your business logic and database access layers. 🧩 @Entity, @Table → Map your Java classes and fields to database tables and columns. ⚙️ @Autowired → Enables automatic dependency injection, letting Spring manage your objects. 💡 These annotations make Spring Boot applications clean, modular, and easy to build! #SpringBoot #Java #BackendDevelopment #SpringFramework #Developers
To view or add a comment, sign in
-
Spring Boot Scenario-Based Questions Here are some real-world Spring Boot scenarios you might face during development : Scenario 1: You are working on a Spring Boot application that requires loading different configurations for development and production environments. How to achieve it?... Scenario 2: You have a service class that needs to be injected into multiple controllers. What are the different ways to achieve this in Spring Boot? Scenario 3: You have a REST API, and when an invalid ID is provided, it should return a custom error message with a 404 Not Found status. How would you handle this? Scenario 4: You need to log events in your application instead of using System.out.println(). How would you do it? Scenario 5: You have an API that fetches user details based on the user Id. How would you capture it in Spring Boot? Which annotation would you use? 💬 Interested ones, share your answers or thoughts in the comments below! #SpringBoot #JavaDevelopers #BackendDevelopment #CodingInterview #SpringFramework #ProblemSolving #Java
To view or add a comment, sign in
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱️ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
☀️ Day 11 of My 90 Days Java Challenge – Collection Classes After exploring the interfaces yesterday, today I moved to their implementations — the actual engines behind the Collections Framework. And that’s where the real differences start to matter. Most tutorials just say “use ArrayList instead of arrays” — but no one tells you why that choice can make or break your code later. Here’s what I discovered 👇 🔹 1️⃣ List Implementations — performance is personality ArrayList → great for search, slow for inserts. LinkedList → perfect for frequent adds/removes, not random access. These tiny performance tradeoffs define real-world efficiency — something you only learn by profiling, not by reading. 🔹 2️⃣ Set Implementations — order and uniqueness HashSet → fast but unordered. LinkedHashSet → remembers insertion order. TreeSet → keeps elements sorted. Choosing between them isn’t just syntax — it’s about data intention. 🔹 3️⃣ Map Implementations — keys tell the story HashMap → fastest for lookups. LinkedHashMap → predictable iteration order. TreeMap → sorted keys, great for range-based operations. Many developers ignore these nuances and end up writing slow, unpredictable code. 🔹 4️⃣ Real-world lesson: The best developers don’t memorize collections — they choose based on behavior, access patterns, and constraints. 💭 Key takeaway: Every collection class tells a story of trade-offs. Knowing why and when to use each one is the skill that turns code into craftsmanship. #Day11 #Java #CoreJava #Collections #JavaDeveloper #LearningJourney #90DaysChallenge
To view or add a comment, sign in
-
⚙️ Learning CRUD Operations in Spring Boot! I explored one of the most important parts of backend development — CRUD operations (Create, Read, Update, Delete) in Spring Boot. What amazed me is how simple Spring Boot makes it: ✅ Just by using JPA and annotations, we can handle database operations that would normally take dozens of lines in plain JDBC. ✅ The flow becomes clean — Controller → Service → Repository → Database. ✅ And with minimal setup, we can perform full database interactions effortlessly. It’s fascinating to see how every step in learning Spring Boot connects — from basic configuration to building real APIs. 💡 Start small, stay consistent, and growth becomes natural. #SpringBoot #CRUD #Java #BackendDevelopment #LearningJourney #Coding #Persistence #Developer
To view or add a comment, sign in
-
-
✅ Day 3 of My Spring Boot Knowledge Series! Field vs Setter vs Constructor Injection – Which one should we actually use? 🤔 In Spring Boot, there are 3 ways to inject dependencies. All work, but not all are best practice. Let’s break it down: --- 🔹 1️⃣ Field Injection (@Autowired on field) @Autowired private UserService userService; ✅ Simple to write ❌ Not recommended (harder to test, allows null, hides dependencies) --- 🔹 2️⃣ Setter Injection (via setter method) private UserService userService; @Autowired public void setUserService(UserService userService) { this.userService = userService; } ✅ Flexible (dependency can change) ✅ Good when dependency is optional ❌ Still allows object creation without dependency (risk of NPE) --- 🔹 3️⃣ Constructor Injection ✅ (Best Practice) private final UserService userService; public UserController(UserService userService) { this.userService = userService; } ✅ Makes class immutable ✅ Dependency is required and guaranteed ✅ Easier unit testing ✅ Works great with Lombok @RequiredArgsConstructor ✅ Avoids NullPointerException --- 🚀 Conclusion: ✅ Use Constructor Injection (Recommended) ➖ Use Setter Injection only when dependency is optional ❌ Avoid Field Injection (not clean, not testable) --- 💬 What’s your preferred injection method and why? Drop your thoughts in the comments! 👇 #SpringBoot #Java #DependencyInjection #CleanCode #BestPractices #LearningJourney #Day3 #SoftwareEngineering
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