🌱 My Spring Journey : @Value Annotation in Spring This annotation is basically used to inject values into simple-type Spring bean properties. 🔹 There are different ways of injecting simple values into Spring bean properties : -> To inject direct values into Spring bean properties. -> To inject values gathered from a properties file. -> To inject system property values like os.name, os.version, etc. -> To inject environment variable values into Spring bean properties. 🔹 We can provide direct values to the @Value annotation, or we can specify a key using a placeholder @Value("${...}"). Difference between @Autowired and @Value : -> @Autowired is used to inject one Spring bean class object into a property (HAS-A relationship) of another Spring bean class. -> @Value is used to inject simple values into the properties of a Spring bean class. 🔹 Internal working : -> The moment the IOC container is created, it internally creates a built-in object called the Environment object, which dynamically collects : -> Key-value pairs defined in the configured properties file. -> Key-value pairs of fixed system properties. -> Environment variable names and their values. Later, these values are injected into Spring bean properties based on the @Value annotation. #SpringFramework #SpringBoot #Java #BackendDevelopment #DependencyInjection #LearningInPublic #MySpringJourney
Spring @Value Annotation for Injecting Values into Bean Properties
More Relevant Posts
-
Polymorphism isn't magic. It's a Lookup Table. I wrote Java for 3 years before I actually understood how the JVM handles Overriding. I relied on the standard university rule: "Method calls are determined by the actual Object type, not the Reference type." While this explains what happens, it doesn't explain how. I imagined the JVM frantically "searching" up the inheritance tree at runtime—scanning the Child class, then the Parent—until it found the method. Architecturally, that would be a disaster. If the JVM had to search the hierarchy (O(N)) for every method call, Java would be too slow for high-performance systems. The JVM avoids this search entirely using vTables (Virtual Method Tables). The Scenario: Imagine we have class B extends A. A has a method print() B overrides show() but inherits print() The Mechanics (Visualized below): Load Time: When Class B is loaded, the JVM builds a hidden array of function pointers. The "Cheat": Since B inherits print(), the JVM simply copies the memory address from A's table into B's table. Runtime: When you run A obj = new B() and call obj.show(), the JVM follows the object in Heap, jumps to the fixed index in the vTable, and runs the code. As the diagram shows: Solid Arrow: The overridden method points to the new B.show() code. Dashed Arrow: The inherited method points back to the existing A.print() code. The Lesson: Efficient systems rarely rely on runtime decisions if they can pre-calculate the answer at load time. (PS: I share more System Design deep dives like this on X. Link in comments 👇) #Java #JVM #SystemDesign #SoftwareArchitecture
To view or add a comment, sign in
-
-
Logic: 100%. Syntax: ...Loading? 😅 Today’s LeetCode Daily (Maximum Level Sum of a Binary Tree) was a rollercoaster. I looked at the problem and immediately clicked: "This is a Breadth-First Search (BFS) problem, easy!" 🧠💡 But then came the implementation... I confess, I had to take a quick peek at the docs to remember how to properly set up a Queue in Java for the traversal. It’s funny how you can have the algorithmic logic perfectly mapped out in your head, but the specific syntax decides to take a coffee break. ☕ Got the green checkmark in the end! ✅ Current Status: 🚀 Runtime: Beats 64% 📉 Memory: Beats 56% The logic works, but looking at those charts, I know there's room for improvement. Next goal: diving deeper into optimizing the time complexity and cleaning up the memory usage. Progress > Perfection! #LeetCode #Java #CodingJourney #BFS #SoftwareEngineering #AlwaysLearning
To view or add a comment, sign in
-
-
Day - 34 Longest Common Prefix The problem - Write a function to find the longest common prefix string amongst an array of strings. Example : strs = [“flower”,”flow”,”flight”] -> “fl” strs=[“dog”,”racecar”,”car”] -> “” Brute force - Compare all the characters at each position across the strings, but the time complexity will be O(S), S is sum of all characters and require multiple traversals. Approach Used - Horizontal Scanning •) Handle edge case: if array is null or empty, return "". •) Initialise pref = strs[0], prefLen = prefix.length(). •) while(prefLen > s.length()) or pref doesn't match the beginning of s (or prefix is longer than s) 1 - Reduce prefix length by 1 (prefLen--). 2 - If prefLen becomes 0, no common prefix exists - return "". 3 - Update prefix to pref.substring(0, prefLen). 4 - Continue to next string. •) Return the final pref. Complexity - Time - O(S), total number of characters in all strings. Space - O(1), only used variables. #DSA #Java #SoftwareEngineering #InterviewPrep #LearnToCode #CodeDaily #ProblemSolving
To view or add a comment, sign in
-
-
Day - 35 Isomorphic Strings The problem - Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order. No two characters may map to the same character, but a character may map to itself. Example : s = "egg", t = "add" → true (e→a, g→d) s = "foo", t = "bar" → false (o cannot map to both a and r) Brute force - Try all possible character mappings, exponential complexity. Approach Used - Used Index Tracking Arrays •) Create two arrays of size 200 to store last seen index - indexS[200] tracks last position of each character in s. indexT[200] tracks last position of each character in t. •) Check if lengths are equal - if not, return false. •) Iterate through both strings (index i from 0 to len) •) Get characters: s.charAt(i) and t.charAt(i), check if indexS[s.charAt(i)] != indexT[t.charAt(i)] 1 - If different, the pattern doesn't match → return false. 2 - Update both arrays, indexS[s.charAt(i)] = i + 1, indexT[t.charAt(i)] = i + 1. •) If loop completes, return true. Complexity - Time - O(n), single pass through strings. Space - O(1), fixed-size arrays (200 elements). Note - Track the last position where each character appeared. If patterns don't match, strings aren't isomorphic! #DSA #Java #SoftwareEngineering #InterviewPrep #LearnToCode #CodeDaily #ProblemSolving
To view or add a comment, sign in
-
-
🧠Array Memory Model & Random Access Mechanism ✅ An array is an object and is always stored in heap memory. 🔑 Contiguous Memory Allocation JVM looks for a continuous block of memory Size required = (size of data type × number of elements) Example: int[] arr = new int[5]; int = 4 bytes Total = 5 × 4 = 20 bytes JVM allocates 20 continuous bytes in heap 3️⃣ Address vs Index vs Value (VERY IMPORTANT) They are three different things 👇 Address ----- Actual memory location (hidden from Java developer) IndexPosition ----- number (0, 1, 2, …) Value ----- Data stored at that position 📌 You never see addresses in Java 📌 You only work with indexes 4️⃣ How does JVM access arr[i] so fast? This is the key concept you’re describing 👇 🔑 Direct Address Calculation (Random Access) Internally JVM does something like: address = baseAddress + (index × sizeOfDataType) Example: arr[3] JVM knows base address of arr Knows int = 4 bytes Calculates: base + (3 × 4) 👉 No loop, no search, no traversal 👉 Direct jump to memory location 📌 This is why arrays are very fast for reading 5️⃣ Why arrays are fast for READ but slow for WRITE? ✅ Fast Read Because of random access JVM jumps directly to the address ❌ Slow Insert / Delete Size is fixed To insert in middle: Shift elements Adjust values Cannot resize memory 📌 This is why arrays are rigid 6️⃣ Can we insert into an array? ❌ No. Arrays are fixed size Once created: new int[5]; Size = 5 forever JVM cannot resize that memory block 👉 Any “insertion” means: Create a new array Copy old values Add new value 📌 This is expensive 🧠 Java Memory — Objects & References (Quick Clarity) 👉 Objects (including arrays) are stored in the Heap 🧱 👉 Reference variables are stored in the Stack 📍 👉 The reference variable stores the base address of the object, ✔️ not the value ✔️ not index 0 ✔️ but the starting address of the array object itself 👉 Inside memory, each address holds both location + actual value 📦 🔖 Frontlines EduTech (FLM) #Java #JVM #HeapMemory #StackMemory #ProgrammingConcepts #JavaInternals
To view or add a comment, sign in
-
-
LeetCode Practice - 944. Delete Columns to Make Sorted 🧠 Problem Idea ✅ You are given n strings, all of the same length. ✅ Imagine them written one below another like a grid. Example: cba daf ghi We check column by column. Column 0 → c d g → sorted ✅ Column 1 → b a h → NOT sorted ❌ Column 2 → a f i → sorted ✅ So we delete column 1 → answer = 1 🛠️ Key Observation ✅ A column is sorted if characters do not decrease from top to bottom. That means: 📌 strs[0][col] <= strs[1][col] <= strs[2][col] <= ... ✅ If any pair breaks this rule, that column must be deleted. 🚀 Algorithm 🔷 Take number of rows n 🔷 Take the n strings 🔷 For each column 🔷 Compare every row with the next row 🔷 If upperRowChar > lowerRowChar, mark it as invalid 🔷 Count how many columns are invalid #LeetCode #Java #StringHandling #CodingPractice #ProblemSolving #DSA #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
Hello Everyone, Day 19 / #100DaysOfCode LeetCode 1292 — Maximum Side Length of a Square with Sum ≤ Threshold (Medium) Problem (brief): Given an m × n matrix of non-negative integers and a threshold, find the maximum side length of a square submatrix whose sum is ≤ threshold. Why this was tricky (for me): Matrix problems still slow me down. Not because they’re impossible—but because without the right preprocessing, everything turns into brute force chaos. Once again, the editorial clarified the first key idea. Core Idea: Use a 2D prefix sum matrix to compute the sum of any square in O(1) time. Let P[i][j] store the sum of the submatrix (1,1) → (i,j). Then any square sum can be computed as: sum = P[x2][y2] - P[x1-1][y2] - P[x2][y1-1] + P[x1-1][y1-1] Optimized Enumeration Strategy: Naively, we’d use three nested loops: - Top-left corner (i, j) - Side length c But two important optimizations help: 1. Monotonicity: All values are non-negative. If a square of size c exceeds the threshold, any larger square at the same position will also fail → break early. 2. Global Best Tracking: If we’ve already found a valid square of size ans, there’s no point checking sizes ≤ ans again. Start directly from ans + 1. These two observations significantly reduce unnecessary checks. Complexity: - Time: ~ O(m⋅n⋅min(m,n))O(m · n · min(m,n))O(m⋅n⋅min(m,n)) (with strong pruning) - Space: O(m⋅n)O(m · n)O(m⋅n) for prefix sums Takeaway: This wasn’t about inventing a clever trick—it was about recognizing when prefix sums + pruning turn brute force into something practical. Matrix problems are still uncomfortable for me, but at least now I know why the solution works—not just that it works. #Leetcode #DSA #Java
To view or add a comment, sign in
-
-
❓ Why do senior interviews still question the Singleton pattern? Singleton centralizes state. At scale, that state becomes a concurrency, testability, and lifecycle liability. #Java #SingletonPattern #DesignPatterns #Concurrency #SystemDesign #BackendEngineering #CoVaibDeepLearn
🧠 Singleton is not about “only one object”. It’s about class loading, memory visibility, and safe publication. Most Singleton implementations look correct — until concurrency, reordering, and class loaders get involved. This deep dive explains: • Why naive Singleton breaks under multithreading • Class loading guarantees vs runtime guarantees • volatile, happens-before, and safe publication • Double-checked locking — when it works and why • Enum Singleton — what the JVM guarantees for free 📘 Singleton Class — JVM-Level Correctness Built for engineers who want thread-safety by design, not by luck. CoVaib-DeepLearn I documented all of this — including bytecode flow, JVM behavior, GC impact, and interview-grade Q&A — in one deeply structured guide. 📘 Master Java for Interviews & Real-World Systems From OOP → Concurrency → System Design → JVM Internals, explore hands-on, engineer-first learning paths here 👇 🔗 Follow @CoVaib-DeepLearn on LinkedIn https://lnkd.in/gVPR4GjG Also available on: • X → https://lnkd.in/g6YJESVD • YouTube → https://lnkd.in/gjjy2cRM • Meta → https://lnkd.in/ggfKuFkQ • WhatsApp → https://lnkd.in/gcekRnii 🔥 Want the Complete In-Depth Version? 📘 Premium PDF (Gumroad) — Levels 4–7 ✓ JVM mental models ✓ Interview-grade Q&A ✓ Correct Singleton patterns ✓ UML & design reasoning ✓ Production traps 💡 Learn faster. Think deeper. Perform with confidence. — CoVaib DeepLearn #Java #AdvancedJava #JavaInterviews #SingletonPattern #JVMInternals #BackendEngineering #CoVaibDeepLearn
To view or add a comment, sign in
-
🔍 Method Overloading - Simple in Syntax, Subtle in Practice Method overloading looks straightforward on the surface, but in real systems, it can introduce subtle behavior if we’re not careful. At a high level, method overloading allows multiple methods with the same name but different parameter lists. The compiler decides which method to call at compile time based on the method signature. Example: calculate(int a, int b) calculate(double a, double b) calculate(int a, int b, int c) Sounds simple, but here’s where experience kicks in 👇 What I’ve learned using overloading in real projects: • Overloading improves readability when methods represent the same logical action with different inputs • Ambiguous overloads (especially with null, autoboxing, or varargs) can lead to unexpected method resolution • Overusing overloads can reduce clarity, especially in large APIs • In public APIs, fewer well-named methods often age better than many overloaded ones One key thing to remember: Overloading is resolved at compile time, not runtime; unlike overriding, which depends on polymorphism. In enterprise codebases, I’ve found overloading most effective when: • The behavior is conceptually identical • Parameter differences are obvious and intentional • Method names remain expressive, not overloaded for convenience Like many Java features, overloading is powerful, but only when used with restraint and clarity. Curious to hear how others decide when to overload vs when to create separate methods 👇 #Java #SoftwareEngineering #CleanCode #BackendDevelopment #ProgrammingPrinciples
To view or add a comment, sign in
-
-
🚀 Day 99 of #100DaysOfLeetCode 🧩 Problem Solved: 10. Regular Expression Matching Today’s challenge was one of the most conceptually demanding string problems on LeetCode. You’re given: A string s A pattern p containing . and * Rules: . matches any single character * matches zero or more of the preceding element The task is to determine whether the entire string matches the pattern. 🧠 Core Insight: This problem is not about brute-force matching. The real challenge is handling: * matching zero occurrences * matching multiple occurrences Ensuring the entire string is consumed The correct way to think about this problem is: 👉 Dynamic Programming on prefixes 🔑 DP Approach (High-Level): Let dp[i][j] = true if s[0..i) matches p[0..j) Transitions: If characters match or pattern has . If pattern has *, we consider: Zero occurrence of previous character One or more occurrences if characters match This ensures all valid pattern interpretations are covered.⚙️ Complexity: Time Complexity: O(m × n) Space Complexity: O(m × n) 🌟 Key Takeaway: This problem reinforced an important lesson: When a problem has multiple interpretations of a choice, DP is usually the answer. It sharpened my understanding of: DP state definition Pattern matching logic Handling edge cases cleanly This is a true interview-level problem that tests reasoning more than syntax. 🏁 Almost There… Day 99 done. One final step to close this journey. Link:[https://lnkd.in/gxwP7GuH] 🏷️ Hashtags: #100DaysOfLeetCode #Day99 #Problem10 #RegularExpressionMatching #DynamicProgramming #DP #StringAlgorithms #Java #LeetCode #ProblemSolving #CodingJourney #Algorithms #DataStructures #InterviewPreparation #DeveloperJourney #ConsistentLearning
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
@configurationproperty is more better than @value I guess