{"id":4483,"date":"2015-08-11T11:15:29","date_gmt":"2015-08-11T11:15:29","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4483"},"modified":"2015-08-11T11:15:29","modified_gmt":"2015-08-11T11:15:29","slug":"variables","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/variables\/","title":{"rendered":"Variables"},"content":{"rendered":"<h5>In Java, objects are stored with their states in variables. They are acting as containers to hold values during object&#8217;s life scope.<\/h5>\n<h3>How to declare a variable?<\/h3>\n<h5>To declare variable, we require to assign some data type for that variable. Data type defines what kind of value this variable can hold (int, long ,float,String etc.).Variable names are case-sensitive.<\/h5>\n<h3>What is the scope of a variable?<\/h3>\n<h4>1) Instance Variable<\/h4>\n<p>Syntax<\/p>\n<pre>ClassScope ClassName {\r\n     DataType varName;\r\n}\r\n<\/pre>\n<p>Example<\/p>\n<pre>class Person{\r\n     String personName;\r\n}\r\n<\/pre>\n<h5>Here, personName is an instance variable, Each instance of class Person will have separate copy for personName.<\/h5>\n<h4>2) Class variable<\/h4>\n<p>Syntax<\/p>\n<pre>ClassScope ClassName {\r\n     static DataType varName;\r\n}\r\n<\/pre>\n<p>Example<\/p>\n<pre>class Person{\r\n     static String personName;\r\n}\r\n<\/pre>\n<h5>Here, personName is a class variable, It is also known as static variable, All instances of class Person will share the same personName attribute.<\/h5>\n<h4>3) Local Variables<\/h4>\n<p>Syntax<\/p>\n<pre>ReturnType MethodName{\r\n    DataType localVariable;\r\n}\r\n<\/pre>\n<p>Example<\/p>\n<pre>void showLocalVariable(){\r\n    String personName;\r\n}\r\n<\/pre>\n<h5>Here, personName is a local variable, its scope is within method only.<\/h5>\n<h4>4) Parameters<\/h4>\n<p>Syntax<\/p>\n<pre>ReturnType showParameter(DataType1 parameter1,DataType2 parameter2,..,DataType3 parametern){\r\n    \/\/logic part of this method.\r\n}\r\n<\/pre>\n<p>Example<\/p>\n<pre>int addition(int firstNumber,int secondNumber){\r\n   return firstNumber+secondNumber;\r\n}\r\n<\/pre>\n<h5>Here, firstNumber and secondNumber are the parameters,their scope is within method only.<\/h5>\n","protected":false},"excerpt":{"rendered":"<p>In Java, objects are stored with their states in variables. They are acting as containers to hold values during object&#8217;s life scope. How to declare a variable? To declare variable, we require to assign some data type for that variable. Data type defines what kind of value this variable can hold (int, long ,float,String etc.).Variable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4494,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4483"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4483"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4494"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}