Variable
A variable is a named location that holds a value.
Related concepts: NameValueAssignment
Closest Wikipedia entry: Variable (computer science) — In computer programming, a variable is an abstract storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value; or in simpler terms, a variable is a named container for a particular set of bits or type of data (like integer, float, string etc...). A variable can eventually be associated with or identified by a memory address. The variable name is the usual way to reference the stored value, in addition to referring to the variable itself, depending on the context.
Misconceptions about Variable35 documented Misconceptions
Check YourselfAssignmentCopiesObject
Assignment copies the objectCallerFrameContainsCalleeFormal
Stack frame of caller includes variables for callee's formal parametersControlledLocalAccess
One can control access to local variables using access modifiersExpressionAssigns
An expression that reads a variable also updates its value after the evaluationForEachIteratesOverIndices
An enhanced for loop iterates over the indices of an array or a collectionForEachVariableIsElement
One can assign to the variable of an enhanced for statement to store a value in the corresponding array or collection elementForVariableScopeBeyondLoop
The scope of variables declared in a for loop header extends beyond the loopInlineVariableInExpressionTree
The expression tree of an expression involving a variable inlines the variable's definitionLocalVariablesAutoInitialized
Local variables are automatically initializedLoopBodyScopeImpliesLoopLifetime
Lifetime of variables declared in a loop body extends across all loop iterationsMultiReferenceVariable
A reference variable can point to multiple objectsMultiValueVariable
A variable can contain more than one valueMustInitializeFieldInConstructor
Constructors must assign values to all fieldsNoAtomicExpression
Expressions must consist of more than one pieceNoCastIfSameSize
If a variable is at least as big (bit-width) as a value, then no cast is needed to a assign the value to the variableNoLocalVariables
There are no local variablesObjectLabeledWithVariableName
In stack and heap diagrams, an object on the heap is labeled with the name of the variable that refers to itReferenceLabeledWithDynamicType
In stack and heap diagrams, reference variables are labeled with the types of the objects they refer toReferenceToVariable
References can point to variablesThisAsField
this is a special field in the objectThisAssignable
One can assign to thisThisExistsInStaticMethod
this is a local variable, also in static methodsUndeclaredVariables
Variables don't need to be declaredUntypedVariables
Variable declarations don't need a typeUseOfSelfTypeImpliesRecursiveType
If a class has a method that has a local variable, parameter, or return value with the class as its type, the class is a recursive typeVariablesHoldExpressions
= stores an expression in a variableVariablesHoldObjects
A variable of a reference type contains a whole object