Java Program Variable: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
No edit summary
 
m (Text replacement - ". ----" to ". ----")
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A [[Java Program Variable]] is a [[software program variable]] in a [[Java program]] (defined in a [[Java programming language]]).
A [[Java Program Variable]] is a [[Java Program Variable|Java variable]] in a [[Java program]].
* <B><U>Context</U>:</B>
**
** It can be:
* <B>Counter-Example(s):</B>  
*** a [[Java Non-Static Field]].
** a [[Scala Program Variable]], a [[Perl Program Variable]], a [[Python Program Variable]], a [[C++ Program Variable]].
*** a [[Java Class Variable]].
** a [[Java Data Structure]].
*** a [[Java Local Variable]].
* <B>See:</B> [[Strongly-typed Programming Language]].
*** a [[Java Parameter]].
 
* <B><U>Example(s)</U>:</B>  
** a [[Primitive Java Variable]], such as a [[Java char variable]].
* <B><U>Counter-Example(s)</U>:</B>
** a [[Python Variable]].
** a [[C++ Variable]].
* <B><U>See</U>:</B> [[Java Data Structure]], [[Strongly-typed Programming Language]].
----
----
----
----
==References==


===2010===
== References ==
* http://download.oracle.com/javase/tutorial/java/nutsandbolts/variables.html
** <U>QUOTE</U>: The [[Java programming language]] defines the following kinds of [[Java Variable|variable]]s:
*** [[Java Instance Variable|Instance Variable]]s ([[Java Non-Static Field|Non-Static Field]]s) Technically speaking, objects store their individual states in "[[Java Non-Static Field|non-static fields]]", that is, [[field]]s declared without the static keyword. [[Non-static field]]s are also known as [[Java instance variable|instance variable]]s because their [[value]]s are unique to each [[instance of a class]] (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
*** [[Java Class Variable|Class Variable]]s ([[Java Static Field|Static Field]]s) A [[Java class variable|class variable]] is any [[Java field|field]] declared with the [[static modifier]]; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.
*** [[Java Local Variable|Local Variable]]s Similar to how an object stores its state in fields, a method will often store its temporary state in local variables. The syntax for declaring a [[Java local variable|local variable]] is similar to declaring a [[Java field|field]] (for example, int count = 0;). There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
*** [[Java Parameter|Parameter]]s You've already seen examples of [[Java parameter|parameter]]s, both in the Bicycle class and in the main method of the "Hello World!" application. Recall that the signature for the [[Java main method|main method]] is public static void main(String[] args). Here, the args variable is the parameter to this method. The important thing to remember is that parameters are always classified as "variables" not "fields". This applies to other parameter-accepting constructs as well (such as constructors and exception handlers) that you'll learn about later in the tutorial.


----
----
__NOTOC__
[[Category:Concept]]
[[Category:Concept]]

Latest revision as of 18:39, 17 September 2021