Day 14 – Learning Java Full Stack Today’s let's learn about the most interesting concepts in Java — Recursion. Recursion happens when a method calls itself. A method (or function) is said to be recursive if it solves a problem by calling itself again and again until a stopping condition is met. 🔹 Two Scenarios in Recursion 1️⃣ Indirect Recursion In this scenario, one method calls another method, and that method calls the first method back. Example flow: disp() → test() → disp() → test() → ... This creates a cycle between methods. 2️⃣ Direct Recursion In this scenario, a method calls itself directly. Example idea: display() → display() → display() → ... Important Note- If recursion is not properly controlled using a condition, it will lead to Stack Overflow Error. So every recursive method must have: ✔ A base condition (stopping condition) ✔ A recursive call 🔹 Controlled Recursion Example (Concept) A method prints a value and calls itself with an updated value until a condition becomes false. Example idea: display(1) if value <= 5 → increment → call display again This ensures recursion stops at the right time. Key Takeaway: Recursion is powerful, but it must be used carefully. Without a proper base condition, it can crash the program. Understanding recursion improves logical thinking and prepares you for advanced data structures like trees and graphs. #Java #JavaFullStack #Recursion #ProgrammingBasics #LearningInPublic #CoreJava
Java Recursion Basics: Understanding Indirect & Direct Recursion
More Relevant Posts
-
🚀 Understanding this() and super() in Java When learning Object-Oriented Programming in Java, two important constructor calls every developer must understand are: 👉 this() 👉 super() Let’s break them down simply. 🔹 1️⃣ this() – Call Current Class Constructor this() is used to call another constructor within the same class. ✅ Why use it? Avoid code duplication Reuse constructor logic Improve readability 💻 Example: class Student { String name; int age; Student(String name) { this(name, 0); // Calling another constructor } Student(String name, int age) { this.name = name; this.age = age; } void display() { System.out.println(name + " " + age); } } 👉 Here, this(name, 0) calls the second constructor. 📌 Rule: this() must be the first statement inside the constructor. 🔹 2️⃣ super() – Call Parent Class Constructor super() is used to call the constructor of the parent class. ✅ Why use it? Initialize parent class variables Reuse parent constructor logic Required in inheritance 💻 Example: class Person { String name; Person(String name) { this.name = name; } } class Student extends Person { int age; Student(String name, int age) { super(name); // Calling parent constructor this.age = age; } void display() { System.out.println(name + " " + age); } } 👉 super(name) calls the Person constructor. 📌 Rule: super() must also be the first statement in constructor. If not written, Java automatically adds super() (default). 🔥 Key Differences this()super()Calls current class constructorCalls parent class constructorUsed for constructor chainingUsed in inheritanceRefers to current objectRefers to parent object 💡 Final Thought Understanding this() and super() makes constructor chaining and inheritance much clearer. As a Java learner, mastering these basics strengthens your OOP foundation 💪 #Java #OOP #Programming #BCAStudent #LearningJourney #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 Learning Update: Core Java — Method Overloading & Compile Time Polymorphism Today’s session helped me understand one of the most important OOP concepts in Java — Method Overloading, along with related concepts like compile-time polymorphism, type promotion, and ambiguity. 📌 Key Learnings: ✅ Method Overloading Learned that method overloading is the process of creating multiple methods with the same name within the same class, but with different parameters (number or type). ✅ Compile-Time Polymorphism (Static Binding / Early Binding) Understood that method overloading happens during the compilation phase and is handled by the Java compiler, not the JVM. ✅ Three Rules of Method Overloading Resolution: 1️⃣ Method Name 2️⃣ Number of Parameters 3️⃣ Type of Parameters These rules help the compiler decide which method should be executed. ✅ Type Promotion Learned how Java automatically converts data types to the closest compatible type when an exact method match is not available. ✅ Ambiguity in Method Overloading Explored scenarios where the compiler gets confused when multiple methods match equally, leading to ambiguity errors. ✅ Real-World Understanding A very interesting realization was that we already use method overloading in Java daily — for example, System.out.println() has multiple overloaded versions internally. 💡 Important Insight: Understanding concepts deeply with logic and real examples is much more powerful than just memorizing definitions — especially for technical interviews. Consistent practice and conceptual clarity are key to becoming a confident developer. #Java #CoreJava #Programming #MethodOverloading #OOP #LearningUpdate #CodingJourney #StudentDeveloper TAP Academy
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 6 🔹 Topic: Loops in Java Loops in Java are used to execute a block of code repeatedly until a certain condition is met. Java mainly provides three types of loops: 1️⃣ for Loop Used when the number of iterations is known. Example: public class Main { public static void main(String[] args) { for(int i = 1; i <= 5; i++) { System.out.println(i); } } } 2️⃣ while Loop Used when the number of iterations is not known beforehand. Example: public class Main { public static void main(String[] args) { int i = 1; while(i <= 5) { System.out.println(i); i++; } } } 3️⃣ do-while Loop The do-while loop executes the code at least once even if the condition is false. Example: public class Main { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 💡 Key Point: Loops help automate repetitive tasks and make programs more efficient. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaLoops
To view or add a comment, sign in
-
🚀 Day 15 | Core Java Learning Journey 📌 Topic: Abstraction in Java – Abstract Class Today, I explored Abstract Classes, another important way to achieve Abstraction in Java. 🔹 What is an Abstract Class? ✔️ A class declared with the abstract keyword ✔️ Cannot be instantiated (no objects directly) ✔️ Can contain abstract & concrete methods ✔️ Used as a base/template for other classes 🔹 Key Rules of Abstract Class ✔️ May contain abstract methods (no body) ✔️ May contain normal methods (with body) ✔️ Can have constructors & variables ✔️ Child class must implement abstract methods ✔️ Supports single inheritance only 🔹 Example: abstract class Animal { abstract void sound(); // abstract method void eat() { // concrete method System.out.println("Eating..."); } } class Dog extends Animal { void sound() { System.out.println("Barking..."); } } public class Main { public static void main(String[] args) { Dog d = new Dog(); d.sound(); d.eat(); } } 🔹 Why Use Abstract Classes? ✔️ To provide common base functionality ✔️ To enforce method implementation ✔️ To achieve partial abstraction ✔️ To share code among related classes 📌 Abstract Class vs Interface (Quick Insight) ✔️ Abstract Class → Can have method bodies & state ✔️ Interface → Only method declarations (conceptually) ✔️ Abstract Class → Uses extends ✔️ Interface → Uses implements 📌 Key Takeaway ✔️ Abstract Class = Blueprint + Implementation ✔️ Cannot create objects directly ✔️ Helps build structured class hierarchy Special thanks to Vaibhav Barde Sir for simplifying Abstraction concepts 💻 #CoreJava #JavaLearning #OOP #Abstraction #AbstractClass #JavaDeveloper #LearningJourney
To view or add a comment, sign in
-
-
this() vs super() While learning Java, one important concept that improves code reusability and object initialization is constructor chaining. In Java, constructor chaining can be achieved using this() and super(). 🔹 this() is used to call another constructor within the same class. 🔹 super() is used to call the constructor of the parent class. This mechanism helps developers avoid code duplication and maintain cleaner code structures. Another interesting rule in Java is that this() and super() must always be placed as the first statement inside a constructor, and they cannot be used together in the same constructor because they conflict with each other. Understanding these small concepts makes a big difference when building scalable object-oriented applications. 📌 Important Points this() Used for constructor chaining within the same class. Calls another constructor of the current class. Helps reuse code inside constructors. Optional (programmer can decide to use it). Must be the first statement in the constructor. super() Used for constructor chaining between parent and child classes. Calls the parent class constructor. If not written, Java automatically adds super(). Must also be the first statement in the constructor. Rule ❗ this() and super() cannot exist in the same constructor because both must be the first line. 🌍 Real-Time Example Imagine an Employee Management System. Parent Class Java 👇 class Person { Person() { System.out.println("Person constructor called"); } } Child Class Java 👇 class Employee extends Person { Employee() { super(); // calls Person constructor System.out.println("Employee constructor called"); } } Using this() Java 👇 class Student { Student() { this(101); // calls another constructor System.out.println("Default constructor"); } Student(int id) { System.out.println("Student ID: " + id); } } ✅ Output 👇 Student ID: 101 Default constructor 💡 Real-world analogy super() → A child asking help from their parent first. this() → A person asking help from another method inside the same team. TAP Academy #Java #OOP #Programming #SoftwareDevelopment #JavaDeveloper #Coding
To view or add a comment, sign in
-
Day 13 – Exploring Strings in Java | My Learning Journey Today I continued my journey of learning Java and explored more concepts related to Strings. Strings are one of the most commonly used data types in programming because they help us work with text data effectively. 🔹 1. String Concatenation in Java String concatenation means combining two or more strings into a single string. In Java, this is commonly done using the + operator or the concat() method. Example: String firstName = "Hello"; String secondName = "World"; System.out.println(firstName + " " + secondName); Output: Hello World 🔹 2. Built-in Methods in String Java provides many built-in methods in the String class that help us perform operations easily. Some commonly used methods include: length() – Returns the length of a string charAt() – Returns the character at a specific index toUpperCase() – Converts string to uppercase toLowerCase() – Converts string to lowercase contains() – Checks if a string contains a specific value substring() – Extracts part of a string Example: String text = "Java Programming"; System.out.println(text.toUpperCase()); 🔹 3. StringTokenizer StringTokenizer is used to split a string into multiple tokens based on a delimiter like space, comma, or any other character. Example: import java.util.StringTokenizer; String str = "Welcome to Java"; StringTokenizer st = new StringTokenizer(str); while(st.hasMoreTokens()){ System.out.println(st.nextToken()); } Output: Welcome to Java Understanding string concatenation, built-in string methods, and String Tokenizer helps in handling and manipulating text data efficiently in Java applications. 💡 Every day I’m learning something new and improving my programming skills step by step. #Java #LearningJava #JavaProgramming #CodingJourney #Strings #DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 10 🔹 Topic: Recursion in Java Recursion is a process where a method calls itself to solve a problem. It is mainly used to break down complex problems into smaller, simpler sub-problems. A recursive function must have: ✔ Base Case → condition to stop recursion ✔ Recursive Call → method calling itself Example: Factorial of a Number public class Main { static int factorial(int n) { if (n == 1) { // base case return 1; } return n * factorial(n - 1); // recursive call } public static void main(String[] args) { int result = factorial(5); System.out.println("Factorial: " + result); } } Output: Factorial: 120 ✔ Recursion solves problems by calling the same method repeatedly ✔ Every recursive method must have a base case ✔ Useful for problems like factorial, Fibonacci, tree traversal #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #Recursion
To view or add a comment, sign in
-
As a part of my core java learning journey TAP Academy Today I learn about the String Concatenation in Java String concatenation is the process of combining two or more strings into a single string. In Java, this can be done using the + operator or the concat() method. 1️⃣ Using String Literals (+ operator) When concatenation involves only literals, the result is stored in the String Constant Pool (SCP). Example: "Java" + "Python" = "JavaPython" → stored in SCP 2️⃣ Using Reference Variables When concatenation involves string references, the result is created in the Heap memory. Example: s1 = "Java" s2 = "Python" s1 + s2 = JavaPython → stored in Heap 3️⃣ Reference + Literal Example: s1 + "Python" = JavaPython→ stored in Heap 4️⃣ Literal + Reference Example: "Java" + s2 = JavaPython→ stored in Heap 5️⃣ Using concat() Method The concat() method also combines strings, and the result is always stored in Heap memory. Example: s1.concat(s2) = JavaPython → stored in Heap Understanding how Java handles concatenation helps in optimizing memory usage and improving performance. TAP Academy #Java #String #Programming #FullStackDeveloper #LearningJourney
To view or add a comment, sign in
-
-
🚀 Learning Core Java – Understanding Inheritance Today I explored another important pillar of Object-Oriented Programming — Inheritance. Inheritance is the concept where one class acquires the properties (variables) and behaviors (methods) of another class. It is achieved using the extends keyword in Java. This helps in code reusability, reduces duplication, and builds a relationship between classes. ⸻ 🔹 Types of Inheritance in Java Java supports several types of inheritance: ✔ Single Inheritance One class inherits from one parent class. ✔ Multilevel Inheritance A chain of inheritance (Grandparent → Parent → Child). ✔ Hierarchical Inheritance Multiple classes inherit from a single parent class. ✔ Hybrid Inheritance A combination of multiple types. ⸻ 🔎 Important Concept 👉 In Java, every class has a parent class by default, which is the Object class. Even if we don’t explicitly extend any class, Java automatically extends: java.lang.Object This means: • Every class in Java inherits methods like toString(), equals(), hashCode(), etc. • The Object class is the root of the class hierarchy. ⸻ 🚫 Not Supported in Java (via classes) ❌ Multiple Inheritance One class inheriting from multiple parent classes is not supported in Java (to avoid ambiguity). 👉 However, it can be achieved using interfaces. ❌ Cyclic Inheritance A class inheriting from itself (directly or indirectly) is not allowed. ⸻ 💡 Key Insight Inheritance promotes: ✔ Code reuse ✔ Better organization ✔ Logical relationships between classes And remember: 👉 All classes in Java ultimately inherit from the Object class. ⸻ Understanding inheritance is essential for building scalable and maintainable Java applications. Excited to keep strengthening my OOP fundamentals! 🚀 #CoreJava #Inheritance #ObjectOrientedProgramming #JavaDeveloper #ProgrammingFundamentals #LearningJourney #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
DAY 22 : CORE JAVA 🔹 Understanding "this" Keyword vs "this()" Method in Java 🔹 While learning Java, one common confusion is the difference between the "this" keyword and the "this()" method. Let’s break it down in a simple way 👇 ✅ 1️⃣ "this" Keyword The "this" keyword refers to the current object of a class. 📌 It is mainly used to: - Resolve variable shadowing (when instance variables and constructor/method parameters have the same name). - Refer to current class instance variables. - Call current class methods. 💡 Example: class Student { String name; Student(String name) { this.name = name; // Resolves shadowing problem } } Here, "this.name" refers to the instance variable, while "name" refers to the constructor parameter. 👉 "this" can be used in any line of a constructor or method. ✅ 2️⃣ "this()" Method The "this()" method is used for constructor chaining — calling one constructor from another constructor within the same class. 📌 Key Rule: - "this()" must always be the first statement inside a constructor. - It cannot be used inside regular methods. 💡 Example: class Student { String name; int age; Student() { this("Unknown", 0); // Calls parameterized constructor } Student(String name, int age) { this.name = name; this.age = age; } } 👉 This improves code reusability and avoids duplication. 🔎 Key Differences "this" Keyword| "this()" Method Refers to current object| Calls another constructor Used to resolve shadowing| Used for constructor chaining Can be used in methods & constructors| Used only inside constructors Can appear anywhere in method/constructor| Must be first statement in constructor 💬 Mastering small concepts like "this" and "this()" builds a strong foundation in Object-Oriented Programming. Keep learning. Keep building. 🚀 TAP Academy #Java #OOP #Programming #SoftwareDevelopment #CodingJourney
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
Which book is it?