this vs super in Java – Simple Explanation 🎯 🔹 this keyword: ▸ Refers to the current class object ▸ this.variable → access current class variable ▸ this() → call current class constructor ▸ Used to resolve naming conflicts class Student { String name; Student(String name) { this.name = name; // refers to current object } } 🔹 super keyword: ▸ Refers to the parent class object ▸ super.variable → access parent class variable ▸ super() → call parent class constructor ▸ Used to access overridden methods class Dog extends Animal { void sound() { super.sound(); // calls Animal's sound() System.out.println("Bark"); } } 🔑 Key Difference: → this = current class → super = parent class 💡 Both can access constructors, variables, and methods — but direction matters: this → inward | super → upward 🔥 Pro Tip: Use this() and super() carefully they must be the first statement in constructor. #Java #CoreJava #OOP #JavaDeveloper #BackendDeveloper #Programming
this vs super in Java: Key Differences and Usage
More Relevant Posts
-
this vs super in Java – Simple Explanation 🎯 🔹 this keyword: ▸ Refers to the current class object ▸ this.variable → access current class variable ▸ this() → call current class constructor ▸ Used to resolve naming conflicts class Student { String name; Student(String name) { this.name = name; // refers to current object } } 🔹 super keyword: ▸ Refers to the parent class object ▸ super.variable → access parent class variable ▸ super() → call parent class constructor ▸ Used to access overridden methods class Dog extends Animal { void sound() { super.sound(); // calls Animal's sound() System.out.println("Bark"); } } 🔑 Key Difference: → this = current class → super = parent class 💡 Both can access constructors, variables, and methods — but direction matters: this → inward | super → upward 🔥 Pro Tip: Use this() and super() carefully they must be the first statement in constructor. #Java #CoreJava #OOP #JavaDeveloper #BackendDeveloper #Programming
To view or add a comment, sign in
-
-
🧱 SOLID Principles in Java – Write Code That Doesn't Come Back to Haunt You You know that feeling when touching one feature breaks three unrelated things? That's what life looks like without SOLID principles. I just published a deep-dive post covering all five principles with real Java examples: ✅ Single Responsibility – One class, one job. Stop your Invoice class from moonlighting as a printer AND a database. ✅ Open/Closed – Extend behavior without cracking open existing code. No more endless if-else chains. ✅ Liskov Substitution – Your Penguin shouldn't throw UnsupportedOperationException when asked to fly. ✅ Interface Segregation – Stop forcing Robots to implement an eat() method. ✅ Dependency Inversion – Depend on abstractions, not implementations. Your service shouldn't care if it's MySQL or PostgreSQL. 🔗 Read the full post: https://lnkd.in/gfA5g8VG #Java #SOLID #CleanCode #SoftwareEngineering #OOP #DesignPrinciples #BackendDevelopment #SpringBoot #Programming #TechBlog #100DaysOfCode
To view or add a comment, sign in
-
Day 51-What I Learned In a Day (JAVA) Today I stepped into the next important concept in Java -Non-Static Members. Unlike static members, non-static members belong to an object, not the class. This means they require an instance of the class to be accessed. What are Non-Static Members? Non-static members include: • Non-static variables (instance variables) • Non-static methods • Constructors Key Understanding: 🔹 Instance Variables Each object has its own copy of variables. Changes in one object do not affect another. 🔹 Non-Static Methods These methods can directly access both static and non-static members. They require object creation to be called. 🔹 Object Creation is Mandatory !To access non-static members: ClassName obj = new ClassName(); Important Difference I Learned: • Static → Belongs to class (no object needed) • Non-Static → Belongs to object (object required) What I Realized Today: Understanding non-static members is crucial because real-world applications mainly work with objects. This concept is the base for Object-Oriented Programming (OOP). #Java #OOP #Programming #LearningJourney #DeveloperLife
To view or add a comment, sign in
-
🚀 Java Deep-Dive Questions That Still Make Me Think 🤯 Lately I’ve been revisiting some core Java concepts, and honestly… the deeper you go, the more questions pop up. Here are a few that sparked my curiosity 🔹 When we create an object, the left-side variable just stores a reference… but why isn’t it treated like a simple string or primitive value? 🔹 Why is Java strictly pass-by-value, even for objects? Why not pass references directly? 🔹 What exactly is a “reference data type”? And why is "String" considered one? 🔹 Variable arguments ("...") — how do they actually work under the hood? 🔹 Why can’t constructors be: - "final"? - "static"? - "abstract"? 🔹 Why don’t constructors have a return type? 🔹 Can we define constructors inside interfaces? 🔹 Why must the constructor name match the class name? These are the kinds of questions that separate just coding from truly understanding Java. Curious to hear your thoughts 👇 Which one of these tripped you up the most? #Java #Programming #SoftwareEngineering #CodingInterview #JavaDeveloper #OOP #JVM #TechLearning #Developers #CodeNewbie
To view or add a comment, sign in
-
Java Collections seem straightforward… until edge cases start showing up in real-world code. Here are a few more collection behaviors worth knowing 👇 • Null handling in collections HashMap allows one null key, Hashtable allows none — small difference, big impact. • contains() vs containsKey() Using the wrong one in Map can lead to incorrect checks. • Size vs Capacity (ArrayList) size() is actual elements, capacity is internal storage — confusion can lead to performance issues. • remove() ambiguity in List remove(1) removes by index, not value — use remove(Integer.valueOf(1)) for value. • equals() & hashCode() importance Custom objects in HashSet/HashMap need proper overrides or duplicates may appear. • Iteration order assumptions HashMap order is unpredictable — don’t rely on it unless using LinkedHashMap or TreeMap. • Immutable collections (List.of) They throw UnsupportedOperationException on modification — common runtime surprise. Small collection details like these often lead to big debugging sessions. #Java #BackendDevelopment #Programming
To view or add a comment, sign in
-
-
# Java Collections Framework — explained simply 👇 --- 🔴 What is Collections Framework? A set of classes and interfaces used to store and manipulate data efficiently. --- 🟢 Main Interfaces: • List → Ordered, allows duplicates • Set → Unordered, no duplicates • Map → Key-value pairs • Queue → Follows FIFO (First In First Out) --- ⚡ Common Implementations: • ArrayList → Dynamic array (fast access) • LinkedList → Fast insertion/deletion • HashSet → No duplicates, fast lookup • HashMap → Key-value storage (fast retrieval) --- 💡 Simple Examples: List<String> list = new ArrayList<>(); list.add("Java"); Set<Integer> set = new HashSet<>(); set.add(10); Map<Integer, String> map = new HashMap<>(); map.put(1, "A"); --- 🚀 When to use what? ✔ Use List → when order matters ✔ Use Set → when uniqueness matters ✔ Use Map → when storing pairs ✔ Use Queue → for processing tasks --- ⚡ Reality: Choosing the right collection can improve performance significantly. --- --- #Java #Collections #Programming #DataStructures #BackendDevelopment #DesignPatterns #SystemDesign #Programming #BackendDevelopment
To view or add a comment, sign in
-
-
Day 7 of #100DaysOfCode — Java is getting interesting ☕ Today I explored the Java Collections Framework. Before this, I was using arrays for everything. But arrays have one limitation — fixed size. 👉 What if we need to add more data later? That’s where Collections come in. 🔹 Key Learnings: ArrayList grows dynamically — no size worries Easy operations: add(), remove(), get(), size() More flexible than arrays 🔹 Iterator (Game changer) A clean way to loop through collections: hasNext() → checks next element next() → returns next element remove() → safely removes element 🔹 Concept that clicked today: Iterable → Collection → List → ArrayList This small hierarchy made everything much clearer. ⚡ Array vs ArrayList Array → fixed size ArrayList → dynamic size Array → stores primitives ArrayList → stores objects Still exploring: Set, Map, Queue next 🔥 Consistency is the only plan. Showing up every day 💪 If you’re also learning Java or working with Collections — let’s connect 🤝 #Java #Collections #ArrayList #100DaysOfCode #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
-
🚀 Understanding Class Loading Process in Java If you're diving into Java, one important concept you must understand is the Class Loading Process. Here's a simple breakdown 👇 🔹 1. Class Loader Java uses different class loaders to load classes into memory: - Bootstrap ClassLoader (loads core Java classes) - Platform ClassLoader - Application ClassLoader 🔹 2. Loading The ".class" file is loaded into memory by the class loader. 🔹 3. Linking This step ensures everything is ready for execution: ✔️ Verification – checks bytecode correctness ✔️ Preparation – allocates memory for static variables ✔️ Resolution – replaces symbolic references with actual references 🔹 4. Initialization Static variables and blocks are executed (e.g., "x = 42;"). 💡 Why it matters? Understanding this helps in debugging, performance optimization, and mastering how Java actually runs behind the scenes. #Java #Programming #Coding #OOP #Developers #JavaBasics #Learning
To view or add a comment, sign in
-
-
🚀 Day 53 – Mastering ArrayDeque in Java Today I explored one of the most efficient data structures in Java Collections – ArrayDeque 🔥 📌 Key Learnings: 🔹 ArrayDeque is a resizable array-based Deque (Double Ended Queue) 🔹 Supports insertion & deletion from both ends (front & rear) 🔹 No indexing → cannot use get/set methods 🔹 No null values allowed (throws runtime exception) 🔹 Duplicates & heterogeneous data allowed 🔹 Faster than LinkedList due to no memory overhead ⚙️ Traversal Techniques: ✔ For-each loop ✔ Iterator ✔ Descending Iterator (reverse traversal) 💡 Why ArrayDeque? 👉 O(1) performance for add/remove operations 👉 Best choice for implementing: Stack (LIFO) Queue (FIFO) Deque 🧠 Big Takeaway: ArrayDeque = Fast + Memory Efficient + Flexible (Stack/Queue/Deque in one) Consistency is the key 🔑 — learning something new every day! #Java #DataStructures #ArrayDeque #JavaCollections #CodingJourney #100DaysOfCode #LearningDaily
To view or add a comment, sign in
-
-
🗺️ 8 Java Maps. 8 Different Problems. Which One Do You Actually Need? Most developers default to HashMap for everything. That's like using a hammer for every job in the toolbox. 🔨 Here's the breakdown you didn't get in college: 1️⃣ HashMap → O(1) get/put, no ordering, not thread-safe ✅ Use when: you just need fast key-value lookup 2️⃣ LinkedHashMap → Maintains insertion order via doubly linked list ✅ Use when: building LRU caches or ordered iteration matters 3️⃣ TreeMap → Sorted keys, O(log n), backed by Red-Black tree ✅ Use when: you need range queries like subMap(), floorKey() 4️⃣ Hashtable → Synchronized, no nulls, legacy class ⚠️ Don't use it. Reach for ConcurrentHashMap instead. 5️⃣ ConcurrentHashMap → Thread-safe without locking the whole map ✅ Use when: multiple threads read/write simultaneously 6️⃣ WeakHashMap → Keys are weakly referenced — GC can collect them ✅ Use when: you need memory-sensitive caching (won't cause leaks) 7️⃣ EnumMap → Only enum keys, array-backed, blazing fast ✅ Use when: your keys are a fixed enum — state machines, configs 8️⃣ IdentityHashMap → Uses == instead of .equals() for key comparison ✅ Use when: object identity matters — serialization, graph traversal The rule is simple: Match the map to the problem, not the other way around. Choosing the wrong map is free today. The production bug it causes? Not so free. 🧨 💾 Save this before your next code review. ♻️ Repost if your team still uses Hashtable in 2026. 👇 Which map do you reach for most — and have you ever regretted it? #Java #SoftwareEngineering #Programming #BackendDevelopment #100DaysOfCode #CleanCode #JavaDeveloper #TechTwitter #CodingTips #DataStructures
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