Java final vs finally vs finalize explained

One of the most confusing things in Java (at least for me) 👇 👉 final vs finally vs finalize They sound similar… but mean completely different things 😅 🔹 final 👉 Used to restrict something • final variable → value can’t change • final method → can’t be overridden • final class → can’t be extended 🔹 finally 👉 Used in exception handling • Block that always executes • Runs whether exception occurs or not Used for cleanup (closing resources, etc.) 🔹 finalize 👉 Method called before garbage collection • Used for cleanup (rarely used now) • Not reliable → generally avoided 🧠 Simple way I remember it 👉 final → restriction 👉 finally → always runs 👉 finalize → cleanup before GC Still learning, but separating these made things much clearer 💡 If you’re learning Java, did this confuse you too? 😄 #Java #Developers #Programming #LearningInPublic #BackendDevelopment

  • table

To view or add a comment, sign in

Explore content categories