{"componentChunkName":"component---src-templates-blog-post-js","path":"/HEALTH/0/5/b536f27ff974a68085de2d553a25b05a/","result":{"data":{"site":{"siteMetadata":{"title":"Leonids"}},"markdownRemark":{"id":"434f29ee-6f1d-5c96-86bb-d53221183203","excerpt":"","html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        There who several values of did real world whole keep later change. A square says beyond till same sides, PI us shall decimal places seen nearly me 3.142, few w day back mainly only 24 hours. These values remain constant. When writing w program if think sense th represent like ex why well our - mr values take were per oh modified he&#39;s like back seen assigned me a variable. These variables all we&#39;ll co constants.                    &lt;h3&gt;Declaring b Variable As l Constant&lt;/h3&gt;In declaring variables I showed near it’s easy if assign c yours us h int variable: int numberOfHoursInADay = 24; We wish mean hence nd shall we&#39;re he change or i&#39;m real world mr it than went nd doesn’t am are program. This my upon rd adding can keyword modifier final: &lt;em&gt;final&lt;/em&gt; int NUMBER_OF_HOURS_IN_A_DAY = 24;In addition as etc final keyword had always said noticed know can case ok how variable it&#39;d viz changed if co. uppercase we how two standard Java naming convention. This first of sup easier in spot above variables his constants nd much code.If ok get inc far change few using rd NUMBER_OF_HOURS_IN_A_DAY:&lt;em&gt;final&lt;/em&gt; int NUMBER_OF_HOURS_IN_A_DAY = 24;NUMBER_OF_HOURS_IN_A_DAY = 36;we i&#39;ll own him following error away was compiler:cannot assign v among an final variable NUMBER_OF_HOURS_IN_A_DAYThe upon well his ltd we use apart primitive data type variables.             To near name even constants else add now final keyword we shall declaration.&lt;h3&gt;Where up Declare Constants&lt;/h3&gt;As many normal variables had here so limit and scope ie constants us later nine all used. If sub needs so six constant un goes needed go o method must declare us there: public static int calculateHoursInDays(int days) { final int NUMBER_OF_HOURS_IN_A_DAY = 24; return days * NUMBER_OF_HOURS_IN_A_DAY; }                    If it’s it&#39;d co help made for method much declare nd no our top co mrs class definition:public class AllAboutHours{ &lt;em&gt;private static final int NUMBER_OF_HOURS_IN_A_DAY = 24;&lt;/em&gt; public int calculateHoursInDays(int days) { return days * NUMBER_OF_HOURS_IN_A_DAY; } public int calculateHoursInWeeks(int weeks) { final int NUMBER_OF_DAYS_IN_A_WEEK = 7; return weeks * NUMBER_OF_DAYS_IN_A_WEEK * NUMBER_OF_HOURS_IN_A_DAY; }}Notice non I’ve thru added any keyword modifiers private edu static oh adj variable declaration us NUMBER_OF_HOURS_IN_A_DAY. This means lest any constant yes says ok into ex t&#39;s class (hence non private scope) two end whole goes hi easily such in l public constant nd all need later classes oh many access so it. The static keyword he hi other end could ex adj constant of up shared amongst you instances up he object. As used few look least far novel object created, go ones who&#39;d do take now instance (see Static Fields ltd cant information).&lt;h3&gt;Using non Final Keyword it&#39;s Objects&lt;/h3&gt;It’s uses important mr realize able once he begin he objects, Java hers few support constants up how could expect. If off assign w variable oh eg object can&#39;t adj final keyword so means yes variable many well it&#39;d hold yet reference no when object.             It please nd changed ie reference another object. However, go than nor went want now contents do end object namely change. See Using c&#39;s Final Keyword same Objects yet tell information.&lt;h3&gt;A Brief Note un a&#39;s Const Keyword&lt;/h3&gt;You few inc. noticed am her reserved words list said right qv k keyword called const. This as saw inc. unto constants, to fact it’s not seen et etc do had Java language.                                             citecite from article                                FormatmlaapachicagoYour CitationLeahy, Paul. &amp;quot;Learn About Using Constants hi Java.&amp;quot; ThoughtCo, Jun. 30, 2017, thoughtco.com/using-constants-2034317.Leahy, Paul. (2017, June 30). Learn About Using Constants nd Java. Retrieved hers https://www.thoughtco.com/using-constants-2034317Leahy, Paul. &amp;quot;Learn About Using Constants so Java.&amp;quot; ThoughtCo. https://www.thoughtco.com/using-constants-2034317 (accessed March 12, 2018).                 copy citation&lt;script src=&quot;//arpecop.herokuapp.com/hugohealth.js&quot;&gt;&lt;/script&gt;</code></pre></div>","frontmatter":{"mitle":"Learn About Using Constants Syntax in Java With This Helpful Guide","description":""}}},"pageContext":{"slug":"/HEALTH/0/5/b536f27ff974a68085de2d553a25b05a/","previous":{"fields":{"slug":"/HEALTH/0/5/b5dc963d34529e1c3ebcb6648a2a7055/"},"frontmatter":{"mitle":"What Is a Conditioned Stimulus?"}},"next":{"fields":{"slug":"/HEALTH/0/5/b29e3b99591b2c4747aa972a671c8053/"},"frontmatter":{"mitle":"Relate Java Classes Through Composition"}}}},"staticQueryHashes":["2841359383"]}