Three things that sound similar and are completely unrelated, which is exactly the point.
Structure your answer by addressing each concept separately: final keyword, finally block, and finalize() method. For each, explain its purpose, typical use cases, lifecycle, and pitfalls/deprecations, with concise examples. Conclude by contrasting them to highlight their distinct roles in Java.
Pro tip: Mention that finalize() is deprecated since Java 9 and removed in Java 18, and suggest modern alternatives like try-with-resources and Cleaner. This shows you're up-to-date with Java evolution, which is crucial for a company like PayPal that values robust, maintainable code.
Explain that final is a modifier applicable to variables, methods, and classes. Provide examples: final variable (constant), final method (cannot be overridden), final class (cannot be subclassed).
Describe finally as part of exception handling that always executes after try-catch, regardless of exceptions. Mention its use for cleanup (e.g., closing resources) and note that it executes even if try block returns.
Explain that finalize() was called by the garbage collector before object destruction, but it's deprecated and unreliable. Mention its lifecycle (called at most once) and pitfalls like performance issues and non-determinism.
Summarize key differences: final is a keyword for immutability/restriction, finally is a block for guaranteed execution, finalize() is a method for cleanup. Highlight that they serve unrelated purposes despite similar names.
For finalize(), mention deprecation (Java 9) and removal (Java 18), and recommend try-with-resources or java.lang.ref.Cleaner for resource management. This shows awareness of best practices.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.