🔹 Java OOP Concept – Marker Interface Today I learned about a very interesting concept in Java called a Marker Interface (also known as an Empty Interface). A marker interface is an interface that does not contain any methods. It simply acts as a signal/flag to the JVM. Example: Serializable, Cloneable, RandomAccess 🔹 What actually happens? When a class implements a marker interface, it doesn’t gain functionality — instead it gains permission. The JVM checks: “Does this object implement the marker interface?” ✔ YES → Special behavior is allowed ❌ NO → Java throws an error (like NotSerializableException) 🔹 Real-life example Think of it like an Exam Hall ID Card 🪪 Student + ID card → allowed to write exam Student without ID → not allowed Similarly: Class implements Serializable → object can be saved/transferred Class does NOT implement it → not permitted 🔹 Important Points • Marker interface has no methods • Used as a tag/flag • JVM checks it using instanceof • Changes runtime behavior • Provides permission, not functionality 🔹 What I understood Java not only uses code for behavior, but also uses design signals to control how objects behave inside JVM. Special thanks to my mentors for guidance Saketh Kallepu Anand Kumar Buddarapu Uppugundla Sairam @Codegnan #Java #OOP
Java Marker Interface: Understanding the Concept
More Relevant Posts
-
DAY 20: CORE JAVA 🔷 Understanding Constructors in Java (With Default & Parameterized Concepts) When learning Java, one important concept in OOP is the Constructor. Many beginners confuse it with a normal method — but it plays a very special role in object creation. 🔹 What is a Constructor? A constructor is a special method used to initialize objects.it is build in setter created by java.Constructor is a specialized setter created by java ✔ It has the same name as the class ✔ It does NOT have a return type (not even void) ✔ It is automatically called when an object is created Customer c1 = new Customer(); Here, the constructor is invoked at the time of object creation. 🔹 Default Constructor If we don’t create any constructor, Java automatically provides one. 👉 It is a zero-parameter constructor 👉 Created by the Java compiler 👉 Only works when no user-defined constructor is written Example: public Customer() { cID = 1; cName = "Anu"; cNum = 9918810; } This initializes the object with default values. 🔹 Parameterized Constructor When we want to initialize objects with different values, we use a parameterized constructor. public Customer(int cID, String cName, int cNum) { this.cID = cID; this.cName = cName; this.cNum = cNum; } 🔎 Important: When parameter names and instance variables are the same, we use the this keyword to differentiate them. This avoids confusion and improves clarity. 🔹 Why Constructors Matter? ✔ They ensure object initialization ✔ They improve data consistency ✔ They support constructor overloading ✔ They are a core part of OOP principles 🔹 Key Takeaways • Constructor name = Class name • No return type • Automatically executed during object creation • Can be overloaded • Default constructor is compiler-provided Understanding constructors is the foundation for mastering Encapsulation, Object Creation, and OOP design. If you're learning Java, mastering constructors will make object behavior much clearer 🚀 TAP Academy Sharath R #Java #OOP #Programming #Constructors #SoftwareDevelopment #CodingJourney
To view or add a comment, sign in
-
-
DAY 25: CORE JAVA 🚀 7 Most Important Elements of a Java Class While learning Java & Object-Oriented Programming (OOP), understanding the internal structure of a class is essential. A Java class mainly contains two categories of members: Class-level (static) and Object-level (instance). Here are the 7 most important elements of a Java class: 🔹 1. Static Variables (Class Variables) These variables belong to the class, not to individual objects. They are shared among all objects of the class. 🔹 2. Static Block A static block is used to initialize static variables. It runs only once when the class is loaded into memory. 🔹 3. Static Methods Static methods belong to the class and can be called without creating an object. 🔹 4. Instance Variables These variables belong to an object. Every object created from the class has its own copy. 🔹 5. Instance Block An instance block runs every time an object is created, before the constructor executes. 🔹 6. Instance Methods Instance methods operate on object data and require an object of the class to be invoked. 🔹 7. Constructors Constructors are special methods used to initialize objects when they are created. 💡 Simple Understanding: 📦 Class Level • Static Variables • Static Block • Static Methods 📦 Object Level • Instance Variables • Instance Block • Instance Methods • Constructors ⚠️ Important Rule: Static members can access only static members directly, while instance members can access both static and instance members. Understanding these 7 elements of a class helps build a strong foundation in Java and OOP concepts, which is essential for writing efficient and well-structured programming TAP Academy #Java #JavaDeveloper #OOP #Programming #Coding #SoftwareDevelopment #LearnJava
To view or add a comment, sign in
-
-
🚀 Understanding Interfaces in Java – Important Rules (Part 2) | Core OOP Concepts Continuing my learning journey in Core Java at TAP Academy, I explored more important rules and concepts related to Interfaces in Java. Interfaces play a key role in achieving abstraction, loose coupling, and scalable system design. Here are some additional rules and insights I learned: 🔹 Important Interface Rules 5️⃣ Partially Implemented Interface If a class partially implements an interface, the class must be declared as abstract. 6️⃣ Multiple Interface Implementation A class can implement multiple interfaces because the diamond problem does not occur in interfaces (they do not contain implementation like classes). 7️⃣ Interface Implementation Restriction An interface cannot implement another interface. 8️⃣ Interface Inheritance An interface can extend another interface, allowing hierarchical interface design. 9️⃣ Class Extending & Implementing A class can extend another class and implement multiple interfaces. The correct order is: class Child extends Parent implements Interface1, Interface2 🔟 Variables in Interface Variables declared in an interface are automatically public, static, and final. 1️⃣1️⃣ Marker (Tagged) Interface An empty interface is called a Marker Interface or Tagged Interface. It is used to provide special properties to the objects of a class. 1️⃣2️⃣ Interface Object Creation An object of an interface cannot be created because it contains abstract methods. However, interface references can be created, which helps achieve: ✔ Loose Coupling ✔ Polymorphism ✔ Flexible system design 🔹 Few Built-in Interfaces in Java Some commonly used built-in interfaces include: ✔ Set ✔ List ✔ Queue ✔ Serializable ✔ Comparable ✔ Comparator ✔ Runnable Learning these rules helped me better understand how interfaces enable flexible architecture and promote good object-oriented design practices in Java. Looking forward to exploring more advanced OOP concepts and real-world implementations! 💻✨ #Java #CoreJava #OOPS #Interfaces #Programming #LearningJourney #SoftwareDevelopment #Polymorphism #Abstraction #TAPAcademy TAP Academy
To view or add a comment, sign in
-
-
Day 34 - Rules for Inheritance in Java Inheritance is a fundamental concept of Object-Oriented Programming (OOP) that allows one class to acquire the properties and methods of another class using the extends keyword. 🔹 Basic Rules of Inheritance in Java 1. Use of extends Keyword A subclass inherits from a superclass using the extends keyword. class Child extends Parent { } 2. Single Inheritance Only (for Classes) Java supports only single inheritance for classes. class B extends A { } // Valid class C extends A, B { } // Not Valid 3. Multiple Inheritance via Interfaces Java does not support multiple inheritance with classes, but it supports multiple inheritance using interfaces. class A implements X, Y { } 4. Private Members Are Not Inherited Private variables and methods of a superclass are not directly accessible in the subclass. 5. Constructor Is Not Inherited Constructors are not inherited, but the superclass constructor can be called using super(). 6. super Keyword Usage To access superclass variables To call superclass methods To invoke superclass constructor 7. Method Overriding Rules Method name must be same Parameters must be same Return type must be same (or covariant) Access modifier cannot be more restrictive than the superclass method 8. Final Methods Cannot Be Overridden If a method is declared as final, it cannot be overridden. 9. Final Class Cannot Be Inherited If a class is declared as final, no other class can extend it. 10. Java Does Not Support Hybrid Inheritance (with Classes) Hybrid inheritance is achieved only through interfaces. 🔹 Types of Inheritance in Java 1. Single Inheritance 2. Multilevel Inheritance 3. Hierarchical Inheritance 4. Multiple Inheritance (Through Interfaces Only) 📌 Key Points to Remember Promotes code reusability Represents IS-A relationship Improves maintainability Supports runtime polymorphism
To view or add a comment, sign in
-
-
Java Full Stack Development – Day 13 | Tap Academy Topic Covered: 🔹 Pass by Value vs Pass by Reference 🔹 Different Types of Methods in Java 🔹 Memory Segments in Java (Stack, Heap, Static) 1️⃣ Pass by Value ✔ In Java, primitive variables are passed by value. ✔ A copy of the variable is sent to the method. ✔ Changes inside the method do not affect the original value. Example: int a = 1000; int b; b = a; System.out.println(a); System.out.println(b); Output 1000 1000 2️⃣ Pass by Reference (Objects) ✔ Object reference is passed to methods. ✔ Changes made to the object affect the original object. Example: Car c1 = new Car(); c1.name = "MARUTHI"; c1.noOfSeats = 5; c1.cost = 8.66f; System.out.println(c1.name); System.out.println(c1.noOfSeats); System.out.println(c1.cost); Output MARUTHI 5 8.66 3️⃣ Different Types of Methods Java methods are classified into 4 types: 1️⃣ No Input – No Output 2️⃣ No Input – Output 3️⃣ Input – No Output 4️⃣ Input – Output These help in structuring programs and improving code reusability. 4️⃣ Memory Segments in Java Java uses different memory areas: Static Segment • Stores static variables. Stack Segment • Stores method calls and local variables. • Each method has its own stack frame. Heap Segment • Stores objects created using new. Example Concept: class Calculator { int a = 50; int b = 40; void add() { int c = a + b; System.out.println(c); } } ✔ Object stored in Heap ✔ Method execution stored in Stack Conclusion Today’s session helped in understanding how Java handles data passing, method types, and memory management, which are fundamental concepts for becoming a strong Java Full Stack Developer. #Java #JavaFullStack #TapAcademy #Programming #JavaDeveloper #CodingJourney #LearnJava #FullStackDeveloper #SoftwareDevelopment #JavaLearning
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 29: CORE JAVA 🔗 Constructor Chaining in Java using "super()" (Inheritance) While learning Java OOP concepts, one interesting topic I explored is Constructor Chaining in Inheritance. 📌 What is Constructor Chaining? Constructor chaining is the process of calling one constructor from another constructor. In inheritance, a child class constructor calls the parent class constructor using "super()". This ensures that the parent class variables are initialized before the child class variables. ⚙️ Key Points to Remember • "super()" is used to call the parent class constructor. • It must be the first statement inside the child constructor. • If we don’t explicitly write "super()", Java automatically calls the parent class default constructor. • This mechanism ensures proper initialization of objects in inheritance hierarchy. 💡 Example Scenario Parent Class: class Test1 { int x = 100; int y = 200; } Child Class: class Test2 extends Test1 { int a = 300; int b = 400; } When an object of "Test2" is created, Java first calls the parent constructor, initializes "x" and "y", and then initializes "a" and "b". 📊 Execution Flow 1️⃣ Object of child class is created 2️⃣ Child constructor calls "super()" 3️⃣ Parent constructor executes first 4️⃣ Control returns to child constructor This concept is very important for understanding object initialization, inheritance hierarchy, and memory allocation in Java. 🚀 Learning these small internal mechanisms of Java helps build a strong foundation in Object-Oriented Programming. TAP Academy #Java #OOP #ConstructorChaining #Inheritance #JavaProgramming #SoftwareDevelopment #CodingJourney
To view or add a comment, sign in
-
-
🚀 The Logic Behind Java's Inheritance Restrictions. Ever wondered why you can't just extend multiple classes in Java? It's not a limitation; it's a safety feature designed to keep your code clean and predictable. Here are my learnings of Inheritance session took by Sharath R sir at TAP Academy. Let's dive into Java's Object-Oriented rules of Inheritance: 🔹 The "No-Go" Zone: Multiple & Cyclic Inheritance Java forbids multiple inheritance to prevent the Diamond Shape Problem. If two parents have different versions of the same method, the child class faces ambiguity—it wouldn't know which one to use. Similarly, cyclic inheritance (where Class A extends B and B extends A) is blocked because it's logically impossible in both the real world and the JVM. 🔹 The Object Class is the Root of All Whether you write it or not, every class in Java extends the Object class. This means even "Single Inheritance" often functions as Multi-level inheritance behind the scenes, as your parent class is already inheriting from the root Object. 🔹 Private Members & Constructors Security First: Private members do not participate in inheritance to ensure that encapsulation is never violated. Constructor Chaining: Constructors are NOT inherited. Instead, Java uses the super() call as the first line of any constructor to chain the child's creation to the parent's. 🔹 Java is a "Hybrid" Powerhouse Java is unique because it is: Statically Typed: You must define types while coding. Dynamic: It loads classes into the JVM only when they are needed during execution. Hybrid: It uses both a compiler and an interpreter (JIT) to convert byte code into machine-level language line-by-line. Understanding these architectural choices makes us better developers by helping us write more robust, conflict-free code. 💻✨ #JavaProgramming #CodingTips #OOPS #SoftwareEngineering #TechLearning #JavaInheritance #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 Understanding Java OOP: Aggregation vs Composition Today I explored an important Object-Oriented Programming concept in Java — Association relationships, specifically Aggregation and Composition. Both represent “Has-A” relationships, but the way objects depend on each other is very different. 🔹 Aggregation (Loose Coupling) In aggregation, objects can exist independently. Even if the main object is destroyed, the related object can still exist. 📌 Example: A Mobile Phone and a Charger If the phone stops working, the charger can still exist. ✔ Objects have independent lifecycle ✔ Represents weak relationship ✔ UML symbol: Hollow Diamond 🔹 Composition (Tight Coupling) In composition, objects are strongly dependent on the parent object. If the main object is destroyed, the child object also gets destroyed. 📌 Example: A Mobile Phone and its Operating System (OS) Without the phone, the OS cannot exist. ✔ Objects have dependent lifecycle ✔ Represents strong relationship ✔ UML symbol: Filled Diamond 💡 Key Learning: Understanding these relationships helps in writing clean, scalable, and well-structured Java applications. Every day in my Full Stack Developer learning journey, I’m exploring deeper concepts of Java and Object-Oriented Programming. 🔥 Which relationship do you use more in your projects — Aggregation or Composition? TAP Academy Sharath R Harshit T Let’s discuss in the comments 👇 #Java #JavaDeveloper #ObjectOrientedProgramming #OOPConcepts #Aggregation #Composition #JavaProgramming #ProgrammingConcepts #SoftwareEngineering #CodingJourney #FullStackDeveloper #DeveloperCommunity #TechLearning #ProgrammingLife #100DaysOfCode
To view or add a comment, sign in
-
-
Understanding Future vs CompletableFuture in Java When working with concurrent programming in Java, we often need to execute tasks asynchronously so the main thread does not get blocked. Two important concepts used for this are Future and CompletableFuture. 🔹 What is Future? Future represents the result of an asynchronous computation. It allows a task to run in another thread and returns the result once the computation is completed. Example: ExecutorService executor = Executors.newFixedThreadPool(2); Future<String> future = executor.submit(() -> { Thread.sleep(2000); return "Task Completed"; }); String result = future.get(); System.out.println(result); In this example: • The task runs in a separate thread • Future holds the result of that task Limitations of Future Future has some important limitations: • "get()" blocks the thread until the result is available • Cannot chain multiple asynchronous tasks • Hard to combine multiple Futures together Because of these limitations, Java introduced CompletableFuture in Java 8. 🔹 What is CompletableFuture? CompletableFuture is an enhanced version of Future that supports non-blocking asynchronous programming. It allows us to: • Chain multiple asynchronous tasks • Combine multiple results • Handle exceptions easily Example: CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { return "Processing Completed"; }); future.thenAccept(result -> { System.out.println(result); }); Here: • The task runs asynchronously • Once completed, the result is processed automatically • The main thread does not block 🔹 Why CompletableFuture is powerful • Supports functional programming style • Enables parallel task execution • Improves performance in backend systems 🔹 Real-world use cases In Spring Boot microservices, CompletableFuture can be used for: • Calling multiple APIs in parallel • Processing background tasks • Improving REST API response time Understanding asynchronous programming concepts like Future and CompletableFuture helps developers build scalable and high-performance backend systems. #Java #SpringBoot #Microservices #JavaConcurrency #BackendDevelopment
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