---
title: "What is the difference between final, finally, and finalize in Java?"  
description: "What is the difference between final, finally, and finalize in Java?"  
author: "Revati S Misra"  
published: 2023-04-19  
updated: 2023-04-24  
canonical: https://www.mindstick.com/forum/157929/what-is-the-difference-between-final-finally-and-finalize-in-java  
category: "java"  
tags: ["java", "programs"]  
reading_time: 2 minutes  

---

# What is the difference between final, finally, and finalize in Java?

What is the [difference between final](https://www.mindstick.com/interview/2456/what-is-difference-between-final-finally-and-finalize), finally, and [finalize](https://www.mindstick.com/forum/101/what-is-the-difference-between-finalize-and-dispose) in [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)?

## Replies

### Reply by Aryan Kumar

**final**, **finally**, and **finalize** are all related to different aspects of Java, and they have different meanings and purposes.

1. **final** is a keyword in Java that can be used to declare a variable, method or class. When applied to a variable, it means that the value of that variable cannot be changed after it has been initialized. When applied to a method, it means that the method cannot be overridden in a subclass. When applied to a class, it means that the class cannot be subclassed.
2. **finally** is a keyword in Java that is used in a try-catch-finally block. The code inside the **finally** block will always execute, whether or not an exception is thrown in the try or catch block. This is useful for cleaning up resources, such as closing files or database connections, that were opened in the try block.
3. **finalize** is a method in Java's **Object** class that is called by the garbage collector before an object is garbage collected. It allows an object to perform any necessary cleanup operations before it is destroyed. However, it is important to note that **finalize** is not guaranteed to be called, and it is generally recommended to use other mechanisms, such as the **try-with-resources** statement or a **finally** block, for cleaning up resources


---

Original Source: https://www.mindstick.com/forum/157929/what-is-the-difference-between-final-finally-and-finalize-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
