{"id":25525479,"date":"2022-05-27T15:20:31","date_gmt":"2022-05-27T09:50:31","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25525479"},"modified":"2022-11-23T18:26:41","modified_gmt":"2022-11-23T12:56:41","slug":"what-are-local-variables-in-java-a-detailed-note","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/","title":{"rendered":"What are Local Variables in Java- A Detailed Note"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e10b8c4c144\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e10b8c4c144\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#How_Local_variable_works_in_Java\" >How Local variable works in Java?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#Class_Variables\" >Class Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#Difference_Between_Class_Variables_And_Instance_Variables_In_Java\" >Difference Between Class Variables And Instance Variables In Java\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n<p>In Java, we have a Local variable that can only be defined inside a method; the scope for the local variable is within the block inside which it gets defined. Outside the block, we cannot even access the variable because we do not know in real whether it exists or not. Local variables are useful when we need some temporary variable to hold the values for us inside the block, and we do not require those variables for other methods or for the entire class in java.In such cases, we can define the variable as local in java to fulfill the requirement. In this article, we will see its internal working, implementation, and their usages of how we can use this while programming in java.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522667 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Web-Development-Rectangle.png\" alt=\"Web Development Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Web-Development-Rectangle.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Web-Development-Rectangle-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Web-Development-Rectangle-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Web-Development-Rectangle-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p>As we know that in java, local variables are specific to the block, not outside that; let\u2019s take a look at the syntax for declaring the local variable. See below for better understanding;<\/p>\n<div class=\"code-block code-block-19\"><\/div>\n<p><code>Variable_type varibale_name = value_to_hold;<\/code><\/p>\n<p>As you can see in the above syntax, we can define the local variables like this; let\u2019s take a closer look at the practice syntax, which will give us better clarity for this to understand and start using this in a program for beginners; see below;<\/p>\n<p>e.g. :<\/p>\n<p><code>String demo = \"\"my variable !!;<\/code><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_Local_variable_works_in_Java\"><\/span><strong>How Local variable works in Java?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As we already know what local variables are in java, we will see some basic rules to define the local variable inside the class method in java or inside any block. This variable is very useful when we have to use the variable for a very limited scope in our code; then, we should go with the local variables. They act as temporary variables for us to use hold the vale and vanish when the particular piece of code stops or finishes its execution. In this section first, we will see the rule to define and use the local variables in java then we will see where does java store their local variables let\u2019s get started to see below;<\/p>\n<p><strong>1. Methods with local variable declaration:<\/strong>\u00a0Now, we will have a look at the method creation, and we will define one local variable inside that method. For reference, see the below code;<\/p>\n<div class=\"code-block code-block-17\">\n<div id=\"banner_1\" class=\"five-sixths box-div\">\n<div class=\"five-sixths\">\n<div class=\"two-sixths price-box\">e.g. :<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><code>public String getmsg(){<br \/>\nint temp = 0;<br \/>\nSyste.out.println(temp);<br \/>\n}<\/code><\/p>\n<p>Above is the sample piece of code that we can use to define the local variable; here, we are creating one method to declare and initiate one local variable for us. This scope for this variable is only to the method, not outside the method or other methods present in the class.<\/p>\n<p><strong>2. static local variable:<\/strong>\u00a0In java, we cannot have a static local variable declaring inside a method that is not static here. Because static variables are directly associated with the class level. Let\u2019s take a piece of code that define this scenario and will give us compile-time error while creating it; see below;<\/p>\n<p>e.g. :<\/p>\n<p><code>public void test(){<br \/>\nstatic String teststr = \"hello\"; \/\/ compile time error<br \/>\n}<\/code><\/p>\n<p><strong>3. static local variable inside static method:<\/strong>\u00a0In java, we cannot even define the static variable inside the static method in java. The same problem will happen as above; it will give us a compile-time error. For reference, see the below code;<\/p>\n<p>e.g. :<\/p>\n<p><code>public static void test(){<br \/>\nstatic String teststr = \"hello\"; \/\/ compile time error<br \/>\n}<\/code><\/p>\n<p><strong>4. final local variable:<\/strong>\u00a0In java, we can define the final local variable inside the method. We just need to have the final keyword associated with it. For reference, see the below code;<\/p>\n<p>e.g. :<\/p>\n<p><code>public void test(){<br \/>\nfinal String teststr = \"hello\";<br \/>\n}<\/code><\/p>\n<p><strong>Points to remember while using the local variable in java :<\/strong><\/p>\n<ul>\n<li>Java stores the local variable inside the stack memory space, not in heap memory.<\/li>\n<li>Local variables are specific to the block only, not outside the method block.<\/li>\n<li>Even class other methods cannot even access the local variable; they are not even aware of them.<\/li>\n<li>We cannot create a static local variable because they are specific to the class level.<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Class_Variables\"><\/span><strong>Class Variables<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Class variables are declared using the static keyword. All instances of the class share the same value of the class variable. The value of a class variable can be accessed and modified by using class methods or instance methods. Once the value is modified, all instances of the class are updated to share the same value.<\/p>\n<h3><strong>Declare Class Variables<\/strong><\/h3>\n<p>Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object. Every instance of the class shares a class variable, which is in one fixed location in memory. Any object can change the value of a class variable, but class variables can also be manipulated without creating an instance of the class.<\/p>\n<p>The following is the syntax to declare class variables.<\/p>\n<div class=\"codeme\">\n<pre>&lt;static&gt; &lt;data_type&gt; &lt;variable_name&gt;;<\/pre>\n<\/div>\n<p>where,<br \/>\n<strong>&lt;static&gt;<\/strong>\u00a0implies that all instances of the class share the same static variable<br \/>\n<strong>&lt;data_type&gt;<\/strong>\u00a0is the data type of the variable.<br \/>\n<strong>&lt;variable_name&gt;<\/strong>\u00a0is the name of the variable.<\/p>\n<p>The following code snippet shows the declaration of class variables.<\/p>\n<div class=\"codeme\">\n<pre>class Book{\r\n   static int price=0;\r\n}<\/pre>\n<\/div>\n<h3><strong>Access Class Variables<\/strong><\/h3>\n<p>Class variables are referenced by the class name itself. This makes it clear that they are class variables. The following is the syntax to access class variables.<\/p>\n<div class=\"codeme\">\n<pre>&lt;class_name&gt;.&lt;variable_name&gt;<\/pre>\n<\/div>\n<p>where,<br \/>\n<strong>&lt;class_name&gt;<\/strong>\u00a0is the name of the class where the variable is declared.<br \/>\n<strong>&lt;variable_name&gt;<\/strong>\u00a0is the variable name.<\/p>\n<p>The following code snippet demonstrates how to declare and reference class variables.<\/p>\n<div class=\"codeme\">\n<pre>class LocalDemo{\r\n    static int price=1;\r\n    public static int getCost() {\r\n        return LocalDemo.price;\r\n    } \r\n}<\/pre>\n<\/div>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Java with Entri! Click Here<\/a><\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Difference_Between_Class_Variables_And_Instance_Variables_In_Java\"><\/span><strong>Difference Between Class Variables And Instance Variables In Java\u00a0<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table>\n<tbody>\n<tr>\n<td width=\"308\"><strong>Class Variables<\/strong><\/td>\n<td width=\"308\"><strong>Instance Variables<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"308\">Class variables are declared with\u00a0keyword\u00a0<em>static<\/em>.<\/td>\n<td width=\"308\">Instance variables are declared without\u00a0<em>static<\/em>\u00a0keyword.<\/td>\n<\/tr>\n<tr>\n<td width=\"308\">Class variables are common to all instances of a class. These variables are shared between the objects of a class.<\/td>\n<td width=\"308\">Instance variables are not shared between the objects\u00a0of a class. Each instance will have their own copy of instance variables.<\/td>\n<\/tr>\n<tr>\n<td width=\"308\">As class variables are common to all objects of a class, changes made to these variables through one object will reflect in another.<\/td>\n<td width=\"308\">As each object will have its own copy of instance variables, changes made to these variables through one object will not reflect in another object.<\/td>\n<\/tr>\n<tr>\n<td width=\"308\">Class variables can be accessed using either class name or object reference.<\/td>\n<td width=\"308\">Instance variables can be accessed only through object reference.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25494072 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square.png\" alt=\"\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2021\/10\/Web-Development-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>In Java, we have a Local variable that can only be defined inside a method; the scope for the local variable is within the block inside which it gets defined. Outside the block, we cannot even access the variable because we do not know in real whether it exists or not. Local variables are useful [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25525754,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1882],"tags":[],"class_list":["post-25525479","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-java-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What are Local Variables in Java- A Detailed Note - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are Local Variables in Java- A Detailed Note - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"In Java, we have a Local variable that can only be defined inside a method; the scope for the local variable is within the block inside which it gets defined. Outside the block, we cannot even access the variable because we do not know in real whether it exists or not. Local variables are useful [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-27T09:50:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-23T12:56:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"What are Local Variables in Java- A Detailed Note\",\"datePublished\":\"2022-05-27T09:50:31+00:00\",\"dateModified\":\"2022-11-23T12:56:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\"},\"wordCount\":1045,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png\",\"articleSection\":[\"Articles\",\"Java Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\",\"url\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\",\"name\":\"What are Local Variables in Java- A Detailed Note - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png\",\"datePublished\":\"2022-05-27T09:50:31+00:00\",\"dateModified\":\"2022-11-23T12:56:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png\",\"width\":820,\"height\":615,\"caption\":\"What are Local Variables in Java- A Detailed Note\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"What are Local Variables in Java- A Detailed Note\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What are Local Variables in Java- A Detailed Note - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/","og_locale":"en_US","og_type":"article","og_title":"What are Local Variables in Java- A Detailed Note - Entri Blog","og_description":"In Java, we have a Local variable that can only be defined inside a method; the scope for the local variable is within the block inside which it gets defined. Outside the block, we cannot even access the variable because we do not know in real whether it exists or not. Local variables are useful [&hellip;]","og_url":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-05-27T09:50:31+00:00","article_modified_time":"2022-11-23T12:56:41+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"What are Local Variables in Java- A Detailed Note","datePublished":"2022-05-27T09:50:31+00:00","dateModified":"2022-11-23T12:56:41+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/"},"wordCount":1045,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png","articleSection":["Articles","Java Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/","url":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/","name":"What are Local Variables in Java- A Detailed Note - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png","datePublished":"2022-05-27T09:50:31+00:00","dateModified":"2022-11-23T12:56:41+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/What-are-Local-Variables-in-Java-A-Detailed-Note.png","width":820,"height":615,"caption":"What are Local Variables in Java- A Detailed Note"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/what-are-local-variables-in-java-a-detailed-note\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"What are Local Variables in Java- A Detailed Note"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25525479"}],"version-history":[{"count":6,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525479\/revisions"}],"predecessor-version":[{"id":25548103,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525479\/revisions\/25548103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25525754"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25525479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25525479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25525479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}