💻 DSA – Day 7: Functions & Methods (Java) Today was all about understanding how functions make code cleaner, reusable, and easier to manage. I explored both the fundamentals and some powerful concepts used in real-world programming. ✅ What I learned today 🔹 Introduction to Functions Why we use them and how they help in breaking problems into smaller pieces. 🔹 Function Syntax + Code Demo Writing basic methods and calling them inside main(). 🔹 Parameters vs. Arguments Understanding how data flows into functions. 🔹 What happens in memory? (Call Stack) How Java manages method calls internally. 🔹 Call by Value (in Java) Java always creates a copy of variables when passing them to methods. 🧮 Problems I solved using Functions ✔ Product of two numbers ✔ Finding Factorial ✔ Binomial Coefficient ✔ Check if a number is Prime ✔ Optimized Prime Check ✔ Print all Primes in a Range ✔ Binary → Decimal (with code) ✔ Decimal → Binary (with code) These problems helped me apply concept + logic simultaneously. 🔄 Inbuilt vs User-Defined Methods Learning when to use Java’s built-in methods and when writing your own is better. ➕ Function Overloading Same function name, different parameters → cleaner and flexible code. Explored: Overloading using different parameters Overloading using different data types 📌 Scope in Java Understanding where variables can be accessed: Method Scope Block Scope This helps avoid errors and write structured code. 🚀 Small progress daily = Big progress later Enjoying how each concept connects to the next. Tomorrow I’ll continue leveling up step by step. #DSA #Day7 #Java #Functions #Methods #CodingJourney #100DaysOfCode #LearningInPublic #BCA #ProblemSolving
"Learned Java Functions and Methods on Day 7 of DSA"
More Relevant Posts
-
🚀(5th Nov 2025) Today I Learned: Functions & Methods (Part 2) After understanding the basics of functions in Part 1, today’s focus was on applying those concepts to solve problems and explore method overloading in Java. Here’s what I practiced 👇 1️⃣ Find Factorial — A great way to apply recursion or iteration to solve mathematical problems. 2️⃣ Find Binomial Coefficient — Combining factorial logic and mathematical formulas in functions. 3️⃣ Inbuilt vs User-Defined Methods — Recognizing the balance between using Java’s library methods and writing custom ones. 4️⃣ Function Overloading — Creating multiple methods with the same name but different parameter lists. 5️⃣ Overloading using Parameters — Changing number of parameters to enhance flexibility. 6️⃣ Overloading using Data Types — Same logic, different data types. 7️⃣ Check if a Number is Prime — Revisiting conditionals with loops inside functions. 8️⃣ Optimized Prime Check — Using √n logic for better time complexity. 🧩 Takeaway: Functions aren’t just about reusability — they bring clarity, scalability, and efficiency to every program. #CodingJourney #Functions #DSA #Java #MethodOverloading #Programming #ApnaCollege #LearningInPublic #DeveloperGrowth
To view or add a comment, sign in
-
-
☀️ Day 7 of My 90 Days Java Challenge – Abstraction & Interfaces Today, I dived into Abstraction — a concept that sounds simple but is often skipped or misapplied by many developers. Here’s what stood out 🔹 1. Abstraction is about hiding complexity Many beginners confuse abstraction with encapsulation. Encapsulation protects data, abstraction hides implementation. It’s the principle that lets you focus on what an object does rather than how it does it. Without this, your code becomes cluttered with unnecessary details. 🔹 2. Interfaces are contracts, not just code Interfaces define what methods a class must implement, not how. This is often neglected, but thinking of interfaces as agreements makes designing large systems much easier. It allows multiple classes to implement the same behavior differently without breaking code that relies on the interface. 🔹 3. Abstract classes vs. Interfaces – understand the purpose Abstract classes are for shared behavior with some implementation. Interfaces are for common contracts with no implementation. Misusing either can lead to rigid, unscalable designs. 💭 Key takeaway: Abstraction isn’t a trick — it’s a mindset. It teaches you to focus on design clarity, maintainability, and future scalability. Mastering abstraction is the bridge from writing code to designing systems. #Day7 #Java #CoreJava #OOPs #Abstraction #Interfaces #LearningJourney #90DaysChallenge
To view or add a comment, sign in
-
Why Does Java Often Have So Many Lines of Code? Lately, I’ve been diving deep into Java projects and noticed one recurring thing — Java programs tend to be verbose. A simple task in Java can take more lines compared to languages like Python or JavaScript. Why is that? 1. Strong Typing – Java requires explicit data types for variables, parameters, and return types. This adds clarity but increases code length. 2. Boilerplate Code – Setting up classes, getters/setters, constructors, and exception handling takes multiple lines. 3. Object-Oriented Structure – Encapsulation, inheritance, and abstraction make code modular, but often more verbose. 4. Backward Compatibility – Java prioritizes stability; newer, concise features are slowly introduced. But here’s the silver lining: this verbosity brings clarity, maintainability, and robustness — especially in large-scale applications. So yes, Java may have “more lines of code,” but every line has a purpose. It’s a language that trades brevity for precision and structure. What do you think? Do you prefer concise code or structured verbosity? 🤔 #Java #Programming #SoftwareDevelopment #CleanCode #CodingBestPractices #CodingCommunity #CodeQuality
To view or add a comment, sign in
-
-
Day 28 - of My Java Learning Series 🧠 From Confusion to Clarity: My Interface Revelation Back when I first learned about Java interfaces, I thought I had them figured out: “Interfaces = 100% abstraction. No method bodies allowed.” Simple, right? But today, that belief got a major upgrade. While diving deeper into modern Java, I discovered that interfaces aren’t just abstract contracts anymore — they’ve evolved into something far more powerful. And honestly, it felt like unlocking a hidden level in the language I thought I knew. Here’s how the story unfolded 👇 🔹 Default Methods I was surprised to learn that interfaces can now have method bodies using the default keyword. Why? So we can add new behavior without breaking existing implementations. Think of it as giving interfaces a gentle way to evolve. 🔹 Static Methods These live inside the interface but don’t belong to any instance. Perfect for utility logic — and yes, you call them using the interface name itself. It’s like giving interfaces their own toolbox. 🔹 Private Methods (Java 9+) This one really clicked for me. Private methods help reduce code duplication inside interfaces — especially when multiple default or static methods share logic. They’re invisible to implementing classes, but super useful behind the scenes. 🔹 Private Static Methods (Java 9+) Same idea, but for static logic. They keep things clean, modular, and reusable — all within the interface itself. ✨ What I Took Away Interfaces in Java are no longer just about abstraction. They’re about evolution without disruption, modularity without mess, and power without complexity. I used to think interfaces were rigid. Now I see them as flexible blueprints — capable of growing with our code. #Java #Interfaces #LearningJourney #OOPs #Programming #TechLearning #Java8 #Java9
To view or add a comment, sign in
-
-
☀️ Day 12 of My 90 Days Java Challenge – Iterator & Enumerator: The Hidden Navigators of Collections Today was about something that looks simple on the surface — traversing collections. But behind every loop lies a quiet hero — Iterator and its ancestor, Enumerator. Most developers just use for-each and move on. But understanding these two changes the way you think about how data is accessed and controlled. Here’s what I realized 👇 🔹 1️⃣ Enumerator – the old-school traveler Introduced in legacy classes like Vector and Stack, the Enumerator interface came before the Collections Framework. It’s simple — with just hasMoreElements() and nextElement() — but limited. You can only read data, not modify it while traversing. Still, understanding it gives you insight into how Java evolved toward modern iteration. 🔹 2️⃣ Iterator – the modern navigator Iterator replaced Enumerator for a reason — it’s fail-fast, universal, and safe. Methods like hasNext(), next(), and remove() let you traverse and modify collections while keeping data integrity intact. 🔹 3️⃣ Fail-fast behavior isn’t a bug — it’s protection Many don’t realize why ConcurrentModificationException exists. It’s not an error — it’s Java’s way of protecting your collection from inconsistent states during iteration. It teaches a valuable principle: better to fail fast than to corrupt data silently. 🔹 4️⃣ Behind the scenes of “for-each” Even the simple enhanced for-loop (for(String s : list)) uses an Iterator under the hood. It’s a small reminder that abstraction doesn’t replace understanding — it depends on it. 💭 Key takeaway: Iteration isn’t just about looping — it’s about safe navigation through data. Knowing how Enumerator and Iterator work gives you a deeper respect for how Java ensures consistency, even in motion. #Day12 #Java #CoreJava #Collections #Iterator #Enumerator #LearningJourney #90DaysChallenge
To view or add a comment, sign in
-
⚡ Day 9: Jump Statements in Java Today I explored jump statements — the control breakers that change the normal flow of execution in a program. 💡 What I Learned Today break → Used to exit from a loop or switch statement early. continue → Skips the current iteration and moves to the next one. return → Exits from the current method and optionally returns a value. Jump statements make loops more flexible and improve flow control. 🧩 Example Code public class JumpStatements { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { if (i == 3) { continue; // Skip 3 } if (i == 5) { break; // Stop loop at 5 } System.out.println("i = " + i); } System.out.println("Loop ended"); System.out.println("Sum: " + add(3, 4)); } static int add(int a, int b) { return a + b; // Return statement } } 🗣️ Caption for LinkedIn ⏩ Day 9 – Jump Statements in Java Today I learned about break, continue, and return — the control flow masters in Java! These statements help make loops and methods more powerful by deciding when to stop, skip, or exit. #CoreJava #JavaLearning #CodingJourney #Programming #LearnJava
To view or add a comment, sign in
-
-
💡 𝗝𝗮𝘃𝗮/𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝐂𝐥𝐞𝐚𝐧 𝐂𝐨𝐝𝐞 𝗧𝗶𝗽 🔥 💎 𝗢𝗽𝘁𝗶𝗼𝗻𝗮𝗹.𝗶𝗳𝗣𝗿𝗲𝘀𝗲𝗻𝘁𝗢𝗿𝗘𝗹𝘀𝗲() 𝗳𝗼𝗿 𝗡𝘂𝗹𝗹 𝗦𝗮𝗳𝗲𝘁𝘆 ✅ The 𝗶𝗳𝗣𝗿𝗲𝘀𝗲𝗻𝘁𝗢𝗿𝗘𝗹𝘀𝗲() method is a powerful feature introduced in 𝗝𝗮𝘃𝗮 𝟵 that takes null safety to the next level. It allows you to handle both present and absent values elegantly in a single expression, eliminating the need for verbose null checks and improving code readability. 💡 While 𝗶𝗳𝗣𝗿𝗲𝘀𝗲𝗻𝘁() from Java 8 only handles the present case, 𝗶𝗳𝗣𝗿𝗲𝘀𝗲𝗻𝘁𝗢𝗿𝗘𝗹𝘀𝗲() extends this capability by accepting two parameters: a Consumer for when the value exists and a Runnable for when it's absent. This functional approach makes your code more expressive and less error-prone than traditional if-null patterns. 🔥 𝗔𝗱𝘃𝗮𝗻𝘁𝗮𝗴𝗲𝘀 𝗼𝗳 𝘂𝘀𝗶𝗻𝗴 𝗶𝗳𝗣𝗿𝗲𝘀𝗲𝗻𝘁𝗢𝗿𝗘𝗹𝘀𝗲() ◾Eliminates repetitive if-null checks, making your code more concise and elegant. ◾Prevents NullPointerException errors by forcing explicit handling of absent values. ◾Supports functional programming style with lambda expressions and method references. ◾Works seamlessly with Optional chains using map, filter, and flatMap operations. 🤔 What's your opinion on using Optional in modern Java? #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
💡A method is a function that settled down , inside a class, or wherever belonging felt right. Most languages let you write free-floating functions, but Java doesn’t really have them. The Java Language Specification (JLS) never even uses the word “function.” Instead, it uses the word “method” - behavior that must always belong to something. That’s why in Java you can’t just write println("Hello, World"); Every piece of behavior needs a home, System.out.println("Hello, World"); Or in newer versions such as Java 25, IO.println("Hello, World"); It still belongs to something - a class, an object, or a type reference. 🏠 However, with java.util.function, Java introduced a new way to act functional without ever changing its true nature. These aren’t real functions; they’re functional interfaces, single-method contracts. 🧾 When you write a lambda like x -> x * 2 you’re not creating a standalone function , you’re creating an object that behaves like one. The JVM quietly builds a lightweight instance that points to an underlying method, keeping it anchored in Java’s object-oriented structure. #Java #Programming #Coding #ObjectOriented #SoftwareDevelopment #TechExplained #LearnJava #CodingLife
To view or add a comment, sign in
-
𝗝𝗮𝘃𝗮 𝗥𝗲𝗰𝗼𝗿𝗱𝘀: 𝗔 𝗦𝗼𝗽𝗵𝗶𝘀𝘁𝗶𝗰𝗮𝘁𝗲𝗱 𝗪𝗮𝘆 𝘁𝗼 𝗕𝘂𝗶𝗹𝗱 𝗗𝗧𝗢𝘀 ☕ When Java introduced records, I immediately thought: “Finally, a cleaner way to write DTOs!” A record is a special kind of class designed to hold immutable data, no boilerplate, no setters, just the essentials. With a single line, Java automatically gives you a constructor, getters, and even equals, hashCode, and toString. Because records are immutable, you can’t modify their fields, no setters allowed. And that’s a good thing: immutability makes data safer and easier to reason about, especially in concurrent systems. For me, records are the most elegant way to express DTOs in Java (introduced in version 14 and made permanent in16), concise, expressive, and intentional. What do you think ? Have you used records in your projects? Any drawbacks or lessons learned? 💡 #LearningJourney #CuriosityDriven #Java #developers #JavaDeveloper #Programming #SoftwareEngineering #DTO #CleanCode #TechTips #CodingJourney
To view or add a comment, sign in
-
-
If you’re learning #Java, you’ve probably seen the keywords #static and wondered — what’s the difference between static and non-static methods? 🤔 Let’s break it down 👇 🧩 Static Methods - Belong to the #class, not to any specific object. - Can be called without creating an #object. - Commonly used for utility or helper functions. ⚙️ Non-Static Methods -Belong to objects created from the class. -Need an instance to be called. -Can access both static and non-static members of the class. 🔑 Key takeaway: -Use 'static' when behavior doesn’t depend on 'object' data. Use 'non-static' when the method works with 'instance' variables. 💬 What’s one thing about static that confused you when you first started learning Java? Let’s discuss in the comments 👇 #Java #LearnJava #CodingForBeginners #SoftwareDevelopment #ProgrammingTips #JavaDeveloper #CodeNewbie #TechEducation
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