🐛 Day 3 — Debugging Diaries: My Battle with a NullPointerException Today wasn’t about writing more code — It was about learning how to think like the compiler. I spent hours chasing one bug: 👉 NullPointerException — a classic Java error that humbles every developer. 😅 🔍 The Issue: My code crashed while displaying student data: System.out.println(student.getName()); The problem? ➡️ student was declared but never initialized — null was calling getName(). ⚙️ How I Tracked It Down: 1️⃣ Read the stack trace — it always tells you where, not why. 2️⃣ Printed object states — confirmed student == null. 3️⃣ Checked constructor flow — found the missing new Student(...). 4️⃣ Added null checks and improved initialization logic. 5️⃣ Cleaned up redundant try-catch blocks — made debugging cleaner. Result → Code ran smoothly. Lesson learned permanently. 💪 🧠 Debugging Takeaways: Don’t panic — trace. Errors are clues, not failures. Initialize before you use. Always. Stack traces are friends. Learn to read them like a story. Null checks ≠ fix — proper object flow is. Debugging = logic building. Every fix strengthens your thought process. 💡 Mindset Shift: Now, when I see red errors on the console, I don’t get frustrated — I get curious. Because that’s where real growth happens. Coding builds programs. Debugging builds developers. 🚀 #Java #Debugging #ProblemSolving #CodeEveryday #DeveloperMindset #100DaysOfCode #LearningInPublic #JavaProgramming #SoftwareEngineering #CleanCode #ErrorHandling #BuildInPublic #CodingJourney #SelfTaughtDeveloper #TechMindset #FromMechanicalToSoftware #ProgrammingLife #BugFixing #CodeToLearn #KeepBuilding #SoftwareDeveloper
Debugging Diaries: Overcoming NullPointerException in Java
More Relevant Posts
-
✨ Don’t Use the ELSE Keyword — Simplifying Logic and Improving Readability 💡 One of the most interesting rules from Object Calisthenics is: “Don’t use the ELSE keyword.” At first glance, it seems radical — after all, else is a fundamental part of most programming languages. But when we stop using it, we start writing more linear, readable, and intentional code. In Java, this principle pushes us to design methods that express decisions clearly, avoiding nested logic and long conditional chains. Instead of focusing on what happens otherwise, we focus on the main flow — and that changes everything. 🤔 Why avoid else? ❌ Nested complexity: Each else adds one more level of indentation, making it harder to follow the method’s logic. ❌ Blurry intent: When if and else blocks both contain logic, it becomes harder to see the “happy path.” ❌ Difficult evolution: As rules grow, new else if statements quickly create a tangle of conditions. 🚀 What improves when you remove it? ✨ Simpler flow: By handling edge cases early (using guard clauses), the main path remains clean and focused. ✨ Better readability: The method reads like a short story — straightforward, without mental jumps. ✨ More maintainable code: Fewer nested blocks mean fewer bugs and easier refactoring. #Java #CleanCode #ObjectCalisthenics #Refactoring #CodeQuality #SoftwareDesign #SpringBoot
To view or add a comment, sign in
-
-
Every developer has written something like "fix later". And we all know “later” never comes 😅 At first it’s just a quick hack to ship the release faster. Then it goes to production, it works, and nobody wants to touch it. A year later that “temporary fix” is part of the system and everyone is afraid to change it. Technical debt doesn’t break things right away. It just makes everything slower over time. New features take longer, bugs are harder to fix, and every change feels risky. Refactoring isn’t perfectionism. It’s part of the job. You either clean the code regularly or the code will clean you. What’s the longest “temporary” fix you’ve seen still running in production? 😅 #python #backend #softwareengineering #techdebt #refactoring #programming #developerslife
To view or add a comment, sign in
-
-
📌 Day 155 of Coding - Next Greater Numerically Balanced Number (LeetCode - Medium) 🎯 Goal: Find the smallest integer greater than n such that the count of each digit d in the number is exactly d (for digits 1-7). 💡Approach & Debugging: Used backtracking to generate all “beautiful” numbers following the digit count rule. A helper function generate() recursively built numbers by trying digits 1-7, ensuring that no digit appeared more times than its own value. Checked each generated number using isBeautiful(). After generation, sorted the list and returned the first number greater than n. ✔️ Time Complexity: Exponential (backtracking-based generation, but limited by small constraints). ✔️ Space Complexity: O(1) auxiliary + O(M) list for generated numbers. 🧠 Key Takeaways: Precomputation and pruning (like limiting to 1224444) help keep recursion efficient. Problems mixing digit frequency logic and recursion sharpen number theory intuition. #Day155 #LeetCode #Backtracking #Recursion #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🚀 Day-73 of #100DaysOfCodeChallenge 💡 LeetCode Problem: 3354. Make Array Elements Equal to Zero (Easy) 🧠 Concepts Practiced: Simulation, Array Manipulation, Direction Reversal Logic Today’s problem was all about simulating a dynamic process — starting from a zero element in an array, moving in a chosen direction, and adjusting movement logic as the array updates. It’s a great exercise in understanding flow control and direction-based simulation, where small logical errors can change the entire outcome. Patience and precision made all the difference here. 🔹 Approach: Simulated each possible starting point and direction, tracking movements and reversals until all elements became zero. Focus was on correctness and clear logic rather than over-optimization. ⚙️ Language: Java ⚡ Runtime: 100 ms (Beats 23.49%) 💾 Memory: 43.44 MB (Beats 13.25%) ✅ Result: 584 / 584 test cases passed — Accepted 🎯 Each solved problem reminds me how logic, structure, and consistency build stronger foundations for solving complex challenges ahead 💪 #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #Programming #DeveloperJourney #TechMindset #LearningEveryday #Consistency #Simulation
To view or add a comment, sign in
-
-
🚀 Want to write cleaner, safer, and more reliable code? Most beginners skip Unit Testing, but every professional developer uses it daily whether they’re working in Java, Python, JavaScript, or any other language. In my new video, I break down: 🔹 What Unit Tests actually are 🔹 Why top software engineers never write code without them 🔹 How to create and organize test files 🔹 How to write meaningful test cases 🔹 Assertions, test data, and best practices 🔹 Real-world examples used in modern software development If you're preparing for interviews, learning DSA, or trying to level up as a developer… 👉 This is a skill that instantly makes you stand out. 🎥 Watch the full video here: How to Create & Use Unit Tests https://lnkd.in/dG7bVmWA Let’s build a developer community that writes code we can trust. 🚀 #SoftwareEngineering #UnitTesting #CleanCode #ProgrammingTips #Java #Python #Developers #QualityAssurance #TechLearning #CodeBetter #LearningJourney #TestingAutomation
To view or add a comment, sign in
-
-
🚀 Want to write cleaner, safer, and more reliable code? Most beginners skip Unit Testing, but every professional developer uses it daily whether they’re working in Java, Python, JavaScript, or any other language. In my new video, I break down: 🔹 What Unit Tests actually are 🔹 Why top software engineers never write code without them 🔹 How to create and organize test files 🔹 How to write meaningful test cases 🔹 Assertions, test data, and best practices 🔹 Real-world examples used in modern software development If you're preparing for interviews, learning DSA, or trying to level up as a developer… 👉 This is a skill that instantly makes you stand out. 🎥 Watch the full video here: How to Create & Use Unit Tests https://lnkd.in/dG7bVmWA Let’s build a developer community that writes code we can trust. 🚀 #SoftwareEngineering #UnitTesting #CleanCode #ProgrammingTips #Java #Python #Developers #QualityAssurance #TechLearning #CodeBetter #LearningJourney #TestingAutomation
To view or add a comment, sign in
-
-
💡Beyond Frameworks: The Art of Problem Solving In the ever-changing world of tech, new frameworks, tools, and languages appear every few months. But one thing never changes — the fundamentals of problem-solving. Whether it’s .NET, Java, Python, or JavaScript — each technology is just a different lens to approach the same challenge: solving real-world problems efficiently and elegantly. Frameworks evolve. Syntax changes. But core principles like design thinking, clean architecture, scalability, and clarity in logic remain timeless. Choosing the “best” technology isn’t about hype — it’s about fit. 🔹 Some tools shine for performance-critical systems. 🔹 Others excel in rapid development or scalability. 🔹 And sometimes, the simplest tech solves the most complex problems. At the end of the day, it’s not about what framework you use — It’s about how well you understand the problem you’re solving and the principles guiding your solution. #Technology #ProblemSolving #SoftwareEngineering #Learning #Mindset
To view or add a comment, sign in
-
-
𝐄𝐩𝐢𝐬𝐨𝐝𝐞 𝟏 — 𝐎𝐎𝐏𝐒 𝐢𝐧 𝐉𝐚𝐯𝐚 : 𝐔𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝𝐢𝐧𝐠 𝐂𝐥𝐚𝐬𝐬𝐞𝐬 & 𝐎𝐛𝐣𝐞𝐜𝐭𝐬 + 𝐀𝐫𝐫𝐚𝐲𝐬 𝐯𝐬 𝐂𝐥𝐚𝐬𝐬𝐞𝐬 Before diving into inheritance, polymorphism, or abstraction... Let’s first understand what OOPS really starts with — Classes and Objects 1️⃣𝐖𝐡𝐚𝐭 𝐢𝐬 𝐎𝐎𝐏𝐒 (Object Oriented Programming System) ➔ It’s how Java turns code into real-world logic. Instead of writing random functions, you create objects — like real-world things! 2️⃣ 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐚 𝐂𝐥𝐚𝐬𝐬? ➔ A Class is like a blueprint or template. It defines what an object will contain and how it behaves. Class doesn’t exist in reality — it’s just a design. 3️⃣ 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐚𝐧 𝐎𝐛𝐣𝐞𝐜𝐭? ➔ An Object is the real thing created from that blueprint. It represents something real and specific. Student → Blueprint s → Real student (Object) 4️⃣ 𝐀𝐫𝐫𝐚𝐲𝐬 𝐯𝐬 𝐂𝐥𝐚𝐬𝐬𝐞𝐬 ➔ Ever wondered — both Arrays and Classes store data... so what’s the actual difference between them? 🤔 Array(like lists) → A collection of similar type of data stored together. It can only store values. Class → A blueprint that defines how an object should look and behave. It can store data + behavior (methods) 𝐓𝐡𝐢𝐧𝐤 𝐨𝐟 𝐢𝐭 𝐥𝐢𝐤𝐞 𝐭𝐡𝐢𝐬 : 👉 Array = Cupboard with multiple boxes of the same size (like only books) 👉 Class = Blueprint to design any type of cupboard (with books, clothes, toys...) 𝐍𝐨𝐭𝐞 :- ➔ Use Arrays when you just need to store a bunch of values. ➔ Use Classes when you need to model real-world objects with properties + behaviors. 𝐈𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭 𝐂𝐨𝐧𝐜𝐞𝐩𝐭 :- ➔ Make classes outside main() , create objects inside main(), so that main() just calls the class and doesn’t define it. ➔ In Java, when you create an object but don’t initialize its instance variables, they automatically get default values (null,0,0.0) assigned by the JVM. - Stuti Gupta #OOPsConcepts #Java #LearnJava #CodingJourney #JavaProgramming #ProgrammingBasics #TechCreators #CodeNewbie #CodingMadeEasy #WomenInTech
To view or add a comment, sign in
-
-
🚀 Today’s #Learning: Solved the Climbing Stairs problem 🪜 using Dynamic Programming (Memoization) in #Java 📘 Problem: Given n stairs, you can climb either 1 or 2 steps at a time. How many distinct ways can you reach the top? ❌ Time Complexity: O(2ⁿ) ❌ Space Complexity: O(n) (due to recursion stack) 🧠 Approach 2 — DP with Memoization (Top-Down): Optimized by storing already computed results to avoid re-computation 👇 ✅ Time Complexity: O(n) ✅ Space Complexity: O(n) (DP array + recursion stack) 💡 Next Step: Convert it to a space-optimized bottom-up approach with O(1) space. 🧠 Approach 3 — Space Optimized (Bottom-Up DP) We only need the last two results at any time — just like Fibonacci. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) ⚙️ Super efficient — perfect for large inputs. 💬 Reflection: Loved how this problem builds intuition for Fibonacci-style DP and space optimization. Every step in #DSA makes problem-solving faster and more intuitive! #Java #DSA #DynamicProgramming #ProblemSolving #Algorithms #CodingPractice #SpaceOptimization #LearningEveryday #Striver #Preparation #Leetcode #Programming #Java #DSA #DynamicProgramming #ProblemSolving #Algorithms #CodingPractice #SpaceOptimization #LearningEveryday #Striver #Preparation #Leetcode #Programming
To view or add a comment, sign in
-
🚀 Day 146 / 180 of #180DaysOfCode ✅ Today’s Highlight: Revisited LeetCode 3234 — “Count the Number of Substrings With Dominant Ones.” 🧩 Problem Summary: Given a binary string s, the task is to count how many of its substrings have dominant ones. A substring is considered dominant if: number of 1s ≥ (number of 0s)² This creates an interesting balance check between zeros and ones, pushing you to think about substring ranges, prefix behavior, and efficient counting techniques. 💡 Core Takeaways: Great exercise in string analysis and prefix-based reasoning Highlights how mathematical conditions influence algorithm design Reinforces handling frequency relationships inside a sliding or expanding window Efficient counting becomes essential due to potential O(n²) substrings 💻 Tech Stack: Java ⏱ Runtime: 115 ms (Beats 84.11%) 💾 Memory: 47 MB 🧠 Learnings: Strengthened understanding of substring behavior under unique constraints Refined thinking around optimizing brute-force patterns A good reminder of how theoretical conditions (like squaring zeros) change practical implementation choices 📈 Progress: Today’s problem significantly improved my intuition around constraint-based substring evaluation—valuable for more advanced algorithmic challenges ahead. #LeetCode #Java #Algorithms #SubstringProblems #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #180DaysOfCode #LogicBuilding #LearningEveryday
To view or add a comment, sign in
-
Explore related topics
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