"extends" vs "implements" in Dart — explained with my Java understanding Coming from Java, I used to think: → extends = class/abstract class → implements = interface class But in Dart, things are a bit different— in Dart ↓ extends → reuse + inherit behavior Just like Java: Child class gets all properties & methods You can override if needed Example: Dog extends Animal → Dog already has eat() and sleep() from Animal ✔️ Using this when I want code reuse ***But for "implements", here’s the twist in Dart ↓ In Java, we implement interfaces. But in Dart, there is no interface keyword to create a interface class. Here we can implement any class. When we use implements, we get no code and we must override everything manually It’s like saying: “I agree with your structure, but I’ll write my own logic.” Simple way to remember: extends → reuse code (like Java class inheritance) implements → follow rules (like Java interface) _____ Real-world use (Flutter thinking): extends → when building base classes or reusable logic like, extends "ChangeNotifier" for provider pkg. implements → when you want strict control or custom behavior like, when applying Dependency Inversion Principle or repository pattern. Once I connected this with Java, Dart OOP inheritance started making much more sense. #Flutter #Dart #Java #OOP #LearningInPublic
Dart OOP: Extends vs Implements Explained with Java Comparison
More Relevant Posts
-
🚨 Java is finally fixing “final” — and it’s a BIG deal for backend devs For years, we trusted this: final String name = "Alok"; 👉 Meaning: this value will never change But under the hood… that wasn’t always true 😶 Using reflection: Field f = User.class.getDeclaredField("name"); f.setAccessible(true); f.set(user, "Hacked"); 💥 Your "final" field could still be modified No error. No warning. (Yes, since JDK 5!) --- 🤯 Why was this allowed? Because popular frameworks relied on it: • Jackson / Gson → deserialization • Hibernate → entity hydration • Mockito → mocking • Old DI → field injection 👉 Reflection made it possible to break immutability --- 🚨 What’s changing now? With Java 26 (JEP 500): ➡️ “Prepare to Make Final Mean Final” ✔️ Today: You’ll see warnings ❌ Tomorrow: It will be blocked (error) --- ⚠️ Why this matters This is not just syntax — it impacts: 🔹 Thread safety (immutability = safe concurrency) 🔹 JVM optimizations (compiler trusts "final") 🔹 Security (no hidden mutation) --- 🛠️ What you should do NOW ✅ Prefer constructor injection private final Service service; public MyClass(Service service) { this.service = service; } ✅ Use immutable DTOs (Java Records) public record UserDTO(String name, int age) {} ✅ Update libraries (Jackson, Hibernate, Mockito) ✅ Run your app on newer Java & check warnings --- 💡 Final Thought 👉 “final” was never truly final… until now. And honestly — it’s about time. --- #Java #SpringBoot #Backend #JavaDeveloper #CleanCode #JVM #Programming #SoftwareEngineering
To view or add a comment, sign in
-
🚀 The Invisible Wall in Java Memory - Why Your Code Crashes Even With 32GB RAM Ever encountered this? Exception in thread "main" java.lang.StackOverflowError The server has 32GB RAM. The heap is barely touched. And yet - crash. What’s actually happening Java memory isn’t one big pool. Every thread gets its own stack - typically ~1MB by default. That stack holds: • Method frames • Local primitives • Object references It’s fast. It’s limited. And it’s completely separate from the heap. Deep recursion burns through that 1MB quickly. It doesn’t matter how much heap you have. 𝗦𝘁𝗮𝗰𝗸𝗢𝘃𝗲𝗿𝗳𝗹𝗼𝘄𝗘𝗿𝗿𝗼𝗿 ≠ 𝗢𝘂𝘁𝗢𝗳𝗠𝗲𝗺𝗼𝗿𝘆𝗘𝗿𝗿𝗼𝗿 One means your thread stack is exhausted The other means your heap is exhausted Confusing them costs hours in production debugging. JVM Heap tip • Always set -𝗫𝗺𝘀 and -𝗫𝗺𝘅 explicitly in production • Never rely on JVM defaults - it guesses, and guessing is expensive Common misconception When StackOverflowError hits, the first instinct is: 👉 “Increase the RAM.” Wrong lever entirely. • Stack isn’t heap • You can’t throw hardware at it • Recursion works… until it doesn’t • In production, “until it doesn’t” comes faster than expected The right mental model ✔️ Prefer iteration for deep recursion ✔️ -𝗫𝘀𝘀 controls thread stack size, but tune it only as a last resort ✔️ Set -𝗫𝗺𝘀 and -𝗫𝗺𝘅 explicitly - don’t trust JVM defaults ✔️ Remember: every thread has its own stack ✔️ Treat StackOverflowError as a design signal, not a runtime surprise Memory management isn’t just a C++ concern- every Java engineer should own it too.
To view or add a comment, sign in
-
-
💡 Understanding the var Keyword in Java While learning modern Java, I came across the var keyword — a small feature that makes code cleaner, but only when used correctly. Here’s how I understand it 👇 In Java, when we declare a variable using var, the compiler automatically determines its data type based on the value assigned. For example: java var name = "Akash"; Here, Java infers that name is of type String. ⚠️ One important clarification: It’s not the JVM at runtime — type inference happens at compile time, so Java remains strongly typed. ### 📌 Key Rules of var ✔️ Must be initialized at the time of declaration java var a = "Akash"; // ✅ Valid var b; // ❌ Invalid ✔️ Can only be used inside methods (local variables) ❌ Not allowed for: * Instance variables * Static variables * Method parameters * Return types ### 🧠 Why use var? It helps reduce boilerplate and makes code cleaner, especially when the type is obvious: java var list = new ArrayList<String>(); ### 🚫 When NOT to use it Avoid `var` when it reduces readability: java var result = getData(); // ❌ unclear type ✨ My takeaway: `var` doesn’t make Java dynamic — it simply makes code more concise while keeping type safety intact. I’m currently exploring Java fundamentals and system design alongside frontend development. Would love to hear how you use var in your projects 👇 Syed Zabi Ulla PW Institute of Innovation #Java #Programming #LearningInPublic #100DaysOfCode #Developers #CodingJourney
To view or add a comment, sign in
-
-
⏳ Day 16 – 1 Minute Java Clarity – final Keyword in Java What if something should NEVER change? Use final! 🔒 📌 What is final? The final keyword restricts modification. 👉 It can be applied to variables, methods and classes. 📌 1️⃣ Final Variable: final int SPEED_LIMIT = 120; SPEED_LIMIT = 150; // ❌ Compilation Error! 👉 Once assigned, value can NEVER be changed. ✔ By convention, final variables are written in UPPER_CASE. 📌 2️⃣ Final Method: class Vehicle { final void start() { System.out.println("Engine started!"); } } 👉 Child class CANNOT override this method. ✔ Used when core behavior must stay consistent. 📌 3️⃣ Final Class: final class PaymentGateway { // Cannot be extended } 👉 No class can inherit from a final class. ✔ Example from Java itself → String class is final! 💡 Real-time Example: Think of a traffic system 🚦 Speed limit on a highway = 120 km/h No one can change that rule → that's your final variable! PI value in Math = 3.14159… It never changes → Math.PI is declared final in Java ✅ ⚠️ Interview Trap: final vs finally vs finalize — all different! 👉 final → restricts change 👉 finally → block in exception handling 👉 finalize → called by GC before object is destroyed 💡 Quick Summary ✔ final variable → value can't change ✔ final method → can't be overridden ✔ final class → can't be inherited ✔ String is a final class in Java! 🔹 Next Topic → Access Modifiers in Java Did you know String is a final class? Drop 💡 if this was new! hashtag #Java #JavaProgramming #FinalKeyword #CoreJava #JavaDeveloper #BackendDeveloper #Coding #Programming #SoftwareEngineering #LearningInPublic #100DaysOfCode #ProgrammingTips #1MinuteJavaClarity
To view or add a comment, sign in
-
-
🧠 JVM Memory & Garbage Collection Let me explain Java memory using your HOUSE as an example 🏠👇 🏠 JVM = Your House Your Java app lives here. Different rooms, different purposes. 📦 Heap = The Storeroom All objects go here. Never clean it? It crashes → OutOfMemoryError 💥 Heap has sections: 👶 Young Gen → new stuff (dies fast) 🧓 Old Gen → stuff you kept for years 🏷️ Metaspace → labels about your stuff 🪑 Stack = Your Desk Small, fast. Holds current work (method calls, local variables). Cleans itself when work is done. No GC needed! 🧹 Garbage Collection = Mom Cleaning Your Room “Do you still need this? No? GONE.” Java finds unused objects and removes them automatically. But sometimes GC yells: “EVERYBODY FREEZE while I clean!” ⏸️ These Stop-the-World pauses make apps laggy. 🔧 Choose Your Cleaner: 🟢 G1 → good all-rounder 🔵 ZGC → almost zero pauses 🟡 Shenandoah → low-latency beast 🔴 Serial → tiny apps only 📝 String Pool = Shared Notebook String a = “Hello”; String b = “Hello”; Java keeps ONE copy. Both point to it. Memory saved! 🎯 ⚡ Make Your App Faster: → Create only objects you need → Set unused objects to null → Close DB connections always → Remove unused listeners → Tune heap with -Xms and -Xmx → Profile with VisualVM or JConsole 🚨 Memory Leak Culprits: ❌ Unclosed DB connections ❌ Static lists that grow forever ❌ Listeners never unsubscribed ❌ Huge data in user sessions 🎯 Recap: 🏠 JVM = House 📦 Heap = Storeroom 🪑 Stack = Desk 🧹 GC = Auto cleaner 📝 String Pool = Shared notebook 🚨 Leaks = Stuff you forgot to toss Clean heap = Fast app 🏃💨 #Java #JVM #GarbageCollection #HeapMemory #JavaDeveloper #Programming #CodingTips #SoftwareEngineering #LearnJava #DevCommunity #100DaysOfCode #JavaPerformance #MemoryManagement #CleanCode #JavaInterview #BackendDevelopment
To view or add a comment, sign in
-
🚀 Day -2 JDK, JRE, JVM Journey with Frontlines EduTech (FLM) and Fayaz S JDK:- 👉 JDK means Java Development kit 👉 Which is collection of the following components 1. Java compiler 2. JVM, 3. Java library ** Simple:- JDK = JRE+ Development kit JRE:- JRE means Java Runtime Environment Which is collection of Java library and JVM JRE is an internal partition of JDK **Simple:- JRE = JVM+library needed to run program JVM:- JVM means Java virtual machine It runs Java Byte code It converts Byte code into machine code and makes Java platform Independent. ** Simple:- JVM ----> Engine that runs Java program. JVM has 3 components 1. CLSS 2. Memory management 3. Execution engine 1.CLSS ----> class loader subsystem load all .class files Verifies all .class filed Links Initialises 2. Memory management:- 👉 Method area ---> static variable, static methods ----> Class meta data link Name, package, parent classes 👉 Heap Area:- ---> Instance Variable ----> objects references 👉 Static area:- Collapse time to time It is stores local variables Threads information is have 👉 Program Counters:- Pointing Current instructions Update next instruction 👉 Native stack area:- Related to other languages (C, C++) 3. Execution engine:- 👉 Interprtor Execute the .class file 👉 JIT compiler Just in time compiler Finds the repetitive code Executes in a single shot Hybrid Language 👉 Garbage collector Collection all unused references/ memoryfreeUp. #corejava #JDK #JRE #JVM #FrontlinesEduTech
To view or add a comment, sign in
-
-
Think var in Java is just about saving keystrokes? Think again. When Java introduced var, it wasn’t just syntactic sugar — it was a shift toward cleaner, more readable code. So what is var? var allows the compiler to automatically infer the type of a local variable based on the assigned value. Instead of writing: String message = "Hello, Java!"; You can write: var message = "Hello, Java!"; The type is still strongly typed — it’s just inferred by the compiler. Why developers love var: Cleaner Code – Reduces redundancy and boilerplate Better Readability – Focus on what the variable represents, not its type Modern Java Practice – Aligns with newer coding standards But here’s the catch: Cannot be used without initialization Only for local variables (not fields, method params, etc.) Overuse can reduce readability if the type isn’t obvious Not “dynamic typing” — Java is still statically typed Pro Insight: Use var when the type is obvious from the right-hand side — avoid it when it makes the code ambiguous. Final Thought: Great developers don’t just write code — they write code that communicates clearly. var is a tool — use it wisely, and your code becomes not just shorter, but smarter. Special thanks to Syed Zabi Ulla and PW Institute of Innovation for continuous guidance and learning support. #Java #Programming
To view or add a comment, sign in
-
-
In Java or C#, you can tell if a variable is on stack or heap. In Go, it is a total mystery. In Java or C#, you can usually tell where data lives just by looking at the code. If a type of variable is ↳ value type (like int, float, struct) - goes to stack ↳ reference type (like class objects) - goes to heap Go works differently... Let's say, you created a variable inside a function and return a pointer to it. Where does that variable live ? The honest answer: it depends. Go uses something called escape analysis. The compiler decides if a variable should live on stack or heap. If a variable ↳ does NOT escape the function - goes to stack ↳ escapes the function - goes to heap A variable “escapes” when: → you return its pointer → you store it in a global variable → a closure captures it → the compiler is unsure about its lifetime Sometimes large structs also go to the heap because the stack has size limits. You cannot always tell by just reading the code. Two functions can look almost the same. One uses stack memory. The other uses heap memory. Go quietly makes the decision for you. That’s why it feels mysterious. Does This Actually Matter ? For most developers: No. Most of the time, the compiler makes better decisions than we would manually. But if you need to tune performance, Go has a built-in way to check for escapes: `go build -gcflags="-m" main.go` --- Have you ever used escape analysis to tune the performance of your project ? Let's discuss it in the comments.
To view or add a comment, sign in
-
-
Java has been my primary language for years. Statically typed, multithreading built-in, and one killer feature — the Reflection API: the thing that lets you reach into the guts of an object at runtime. It's what powers Spring, Hibernate, Jackson, and countless other tools and libraries we use every day. Dependency injection, JSON mapping, ORM magic — reflection is the engine underneath most of it. Then I tried Flutter. Flutter runs on Dart, and Dart's equivalent — Mirrors — is disabled. What used to be a no-brainer suddenly required planning. Every data class now needs a toJson() and a fromJson() method written by hand — or generated by tools like json_serializable. At first it felt like a step backward. But here's the thing — there's a reason Mirrors was disabled. Reflection is slow. Every app launch, the JVM is doing expensive runtime introspection. If you've ever stared at a large Spring app refusing to wake up in the morning... you know the feeling. ☕ That's exactly why frameworks like Micronaut and Quarkus exist. Instead of digging into the guts of objects at runtime, they generate all that code at compile time. The result? Blazing fast startup with none of the overhead. Flutter's constraint wasn't a limitation — it was a design choice that pointed toward a better pattern. Sometimes the wall you hit is actually there to protect you. This reminds me of Sourat Al-Kahf — the meeting of Prophet Musa (Moses) and Khodr (Al-Khidr). Every time Khodr did something that seemed wrong or harmful, there was a deeper wisdom behind it that Musa couldn't see yet. The constraint that frustrated him was quietly serving a greater purpose. Sometimes in tech — and in life — the limitation that slows you down is the very thing pushing you toward a better way. #Java #Flutter #SoftwareEngineering #BackendDevelopment #Dart #MobileDev
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