{"id":3261,"date":"2020-03-07T11:02:16","date_gmt":"2020-03-07T05:32:16","guid":{"rendered":"https:\/\/cns72.com\/vytcdc.com.sg\/?p=3261"},"modified":"2020-12-10T20:41:25","modified_gmt":"2020-12-10T15:11:25","slug":"final-classes-methods-variables-and-arguments-in-java","status":"publish","type":"post","link":"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/","title":{"rendered":"Final Classes, Methods, Variables, and Arguments in Java."},"content":{"rendered":"<p>After working with several Java developers of varying skill levels, I have found that the &#8220;final&#8221; keyword is the most underused concept practiced by them. I have found great reasons to use &#8220;final&#8221; in my coding and I wanted to share some of them.<\/p>\n<p><b>Final Class<\/b><\/p>\n<ul>\n<li>A class is called final class when it is declared with the final keyword.<\/li>\n<li>Final class cannot be inherited.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"wp-image-3272 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image1.png\" alt=\"\" width=\"439\" height=\"171\" \/><\/p>\n<ul>\n<li>Why do we want to make a class as final?<\/li>\n<li>When you want to do an immutable programming<\/li>\n<li>If you do not want somebody to extend the class, then use the final class.<\/li>\n<li>Whenever somebody extends a class they have the privilege of modifying some of the code inside those class methods, if we do not want to allow it, in certain situations.<\/li>\n<\/ul>\n<p><b>Example<\/b><br \/>\nAll Wrapper Classes like Integer, Float, etc. are final classes. We cannot inherit them.<br \/>\nNobody will be able to extend the above class.<\/p>\n<p><b>Final Methods<\/b><\/p>\n<ul>\n<li>We can declare some or all methods\u00a0final.<\/li>\n<li>Use the final keyword in a method declaration to indicate that the method cannot be overridden by\u00a0subclasses.<\/li>\n<li>The main intention of making a method final would be that the content of the method should not be changed by any outsider.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\" wp-image-3270 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image2.png\" alt=\"\" width=\"318\" height=\"149\" \/><\/p>\n<p><b>Final Variable<\/b><\/p>\n<p>The only difference between a\u00a0normal variable and a\u00a0final variable is that we can re-assign value to a normal variable but we cannot change the value of a final variable once assigned. Hence, final variables must be used only for the values that we want to remain constant throughout the execution of the program.<\/p>\n<p><b>Example of final variable<\/b><\/p>\n<p><img loading=\"lazy\" class=\" wp-image-3273 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image3.png\" alt=\"\" width=\"380\" height=\"128\" \/><\/p>\n<ul>\n<li>In the above example, we can change the variable i from 5 to 7.<\/li>\n<li>If we do not want to change the value, we will make variable i as final.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\" wp-image-3274 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image4.png\" alt=\"\" width=\"369\" height=\"123\" \/><\/p>\n<p><img loading=\"lazy\" class=\" wp-image-3275 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image5.png\" alt=\"\" width=\"459\" height=\"42\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Here we have declared variable i as final so changing i value is not allowed.<\/li>\n<\/ul>\n<p><b>Final argument<\/b><\/p>\n<p>Here below, we have not declared argument as final.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-3276 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image6.png\" alt=\"\" width=\"374\" height=\"121\" \/><\/p>\n<ul>\n<li>In the bellow example doSomethingElse() method declared as final int argument.<\/li>\n<li>So it\u00a0restrict\u00a0\u00a0to change the value of\u00a0doSomethingElse() method argument.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"wp-image-3271 aligncenter\" src=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/image7.png\" alt=\"\" width=\"441\" height=\"127\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After working with several Java developers of varying skill levels, I have found that the &#8220;final&#8221; keyword is the most underused concept practiced by them. I have found great reasons to use &#8220;final&#8221; in my coding and I wanted to share some of them. Final Class A class is called final class when it is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3278,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[63],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.0.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Final Classes, Methods, Variables, and Arguments in Java. - TCDC<\/title>\n<link rel=\"canonical\" href=\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Final Classes, Methods, Variables, and Arguments in Java. - TCDC\" \/>\n<meta property=\"og:description\" content=\"After working with several Java developers of varying skill levels, I have found that the &#8220;final&#8221; keyword is the most underused concept practiced by them. I have found great reasons to use &#8220;final&#8221; in my coding and I wanted to share some of them. Final Class A class is called final class when it is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"TCDC\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vytcdc\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-07T05:32:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-10T15:11:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/finalkeyword.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"325\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vytcdc\" \/>\n<meta name=\"twitter:site\" content=\"@vytcdc\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#website\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"name\":\"TCDC\",\"description\":\"Career Development Courses\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/cns72.com\/vytcdc.com.sg\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/wp-content\/uploads\/2017\/05\/finalkeyword.jpg\",\"width\":600,\"height\":325},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/#webpage\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\",\"name\":\"Final Classes, Methods, Variables, and Arguments in Java. - TCDC\",\"isPartOf\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/#primaryimage\"},\"datePublished\":\"2020-03-07T05:32:16+00:00\",\"dateModified\":\"2020-12-10T15:11:25+00:00\",\"author\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#\/schema\/person\/c57e5f7b91685a93f23a57aaafd38e82\"},\"breadcrumb\":{\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\",\"url\":\"https:\/\/cns72.com\/vytcdc.com.sg\/final-classes-methods-variables-and-arguments-in-java\/\",\"name\":\"Final Classes, Methods, Variables, and Arguments in Java.\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#\/schema\/person\/c57e5f7b91685a93f23a57aaafd38e82\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/cns72.com\/vytcdc.com.sg\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8f959f70994a4401c8704d6b2143474?s=96&d=mm&r=g\",\"caption\":\"admin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts\/3261"}],"collection":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/comments?post=3261"}],"version-history":[{"count":0,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/posts\/3261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/media\/3278"}],"wp:attachment":[{"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/media?parent=3261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/categories?post=3261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cns72.com\/vytcdc.com.sg\/wp-json\/wp\/v2\/tags?post=3261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}