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 or scalar 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 easy terms, a variable is a container for a particular type of data (like integer, float, String and 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 Variable
35 documented Misconceptions

Check Yourself
Misconception
AssignmentCopiesObject
Assignment copies the object
Misconception
CallerFrameContainsCalleeFormal
Stack frame of caller includes variables for callee's formal parameters
Misconception
ControlledLocalAccess
One can control access to local variables using access modifiers
Misconception
ExpressionAssigns
An expression that reads a variable also updates its value after the evaluation
Misconception
ForEachIteratesOverIndices
An enhanced for loop iterates over the indices of an array or a collection
Misconception
ForEachVariableIsElement
One can assign to the variable of an enhanced for statement to store a value in the corresponding array or collection element
Misconception
ForVariableScopeBeyondLoop
The scope of variables declared in a for loop header extends beyond the loop
Misconception
InlineVariableInExpressionTree
The expression tree of an expression involving a variable inlines the variable's definition
Misconception
LocalVariablesAutoInitialized
Local variables are automatically initialized
Misconception
LoopBodyScopeImpliesLoopLifetime
Lifetime of variables declared in a loop body extends across all loop iterations
Misconception
MultiReferenceVariable
A reference variable can point to multiple objects
Misconception
MultiValueVariable
A variable can contain more than one value
Misconception
MustInitializeFieldInConstructor
Constructors must assign values to all fields
Misconception
NoAtomicExpression
Expressions must consist of more than one piece
Misconception
NoCastIfSameSize
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 variable
Misconception
NoLocalVariables
There are no local variables
Misconception
ObjectLabeledWithVariableName
In stack and heap diagrams, an object on the heap is labeled with the name of the variable that refers to it
Misconception
ReferenceLabeledWithDynamicType
In stack and heap diagrams, reference variables are labeled with the types of the objects they refer to
Misconception
ReferenceToVariable
References can point to variables
Misconception
ThisAsField
this is a special field in the object
Misconception
ThisAssignable
One can assign to this
Misconception
ThisExistsInStaticMethod
this is a local variable, also in static methods
Misconception
UndeclaredVariables
Variables don't need to be declared
Misconception
UntypedVariables
Variable declarations don't need a type
Misconception
UseOfSelfTypeImpliesRecursiveType
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 type
Misconception
VariablesHoldExpressions
= stores an expression in a variable
Misconception
VariablesHoldObjects
A variable of a reference type contains a whole object

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.