{"id":1621,"date":"2016-09-14T12:38:53","date_gmt":"2016-09-14T12:38:53","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1621"},"modified":"2016-09-14T12:38:53","modified_gmt":"2016-09-14T12:38:53","slug":"final-vs-finally-vs-finalize","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/final-vs-finally-vs-finalize\/","title":{"rendered":"final vs  finally vs finalize"},"content":{"rendered":"<p><strong>Final Example<\/strong>]<\/p>\n<ol>\n<li>Final is used to apply restrictions on class, method and variable. Final class can&#8217;t be inherited, final method can&#8217;t be overridden and final variable value can&#8217;t be changed.<\/li>\n<li>Final is a keyword.<\/li>\n<\/ol>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass FinalEg\r\n{\r\n   public static void main(String&#x5B;] args) \r\n   {\r\n      final int x = 600;\r\n      x = 400;\/\/ Compile Time Error\r\n    }\r\n}\r\n<\/pre>\n<p><strong>Finally Example<\/strong><\/p>\n<ol>\n<li>Finally is used to place important code, it will be executed whether exception is handled or not.<\/li>\n<li>Finally is a block.<\/li>\n<\/ol>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass FinallyEg\r\n{\r\n\tpublic static void main(String&#x5B;] args) \r\n\t{\r\n\t\ttry {\r\n\t\t\tint x = 500;\r\n\t\t} catch (Exception e) {\r\n\t\t\tSystem.out.println(e);\r\n\t\t} finally {\r\n\t\t\tSystem.out.println(&quot;finally block is executed&quot;);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>Finalize Example<\/strong><\/p>\n<ol>\n<li>Finalize is used to perform clean up processing just before object is garbage collected. <\/li>\n<li>Finalize is a method.<\/li>\n<\/ol>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass FinalizeEg \r\n{\r\n\tpublic void finalize() \r\n        {\r\n\t   System.out.println(&quot;finalize called&quot;);\r\n\t}\r\n\r\n\tpublic static void main(String&#x5B;] args) \r\n        {\r\n\t\tFinalizeExample f1 = new FinalizeExample();\r\n\t\tFinalizeExample f2 = new FinalizeExample();\r\n\t\tf1 = null;\r\n\t\tf2 = null;\r\n\t\tSystem.gc();\r\n\t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Final Example] Final is used to apply restrictions on class, method and variable. Final class can&#8217;t be inherited, final method can&#8217;t be overridden and final variable value can&#8217;t be changed. Final is a keyword. class FinalEg { public static void main(String&#x5B;] args) { final int x = 600; x = 400;\/\/ Compile Time Error }&hellip; <a href=\"https:\/\/codethataint.com\/blog\/final-vs-finally-vs-finalize\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[193],"tags":[],"class_list":["post-1621","post","type-post","status-publish","format-standard","hentry","category-interview-questions-java"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1621"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1621\/revisions"}],"predecessor-version":[{"id":1622,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1621\/revisions\/1622"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}