sobota, 18 lipca 2015

Variables, Assignment instruction.

Variables are like 'boxes' that can contain something. Variables can have names, or 'labels'. Variables' size is measured in number of bits or bytes, etc ... Variables, can contain a value, a number, a character, or other data.

One can say that we 'put' a value into 'a variable' as into a box.


Other words to express that physical phenomenon is saying i assign value of '3' to a variable named
(labelled as) 'firstNumber'.



it's assignment instruction, depending on notation (syntax) it can be written as:

  first_number = 3;
  first_number := 3;
  firstNumber = 3;

after assigning a value to a variable, variable contains that value in itself, has that value.



we can assign variable's value to another variable as well.

  secondNumber = firstNumber;

often a variable has to be declared before being used, assigned a type & size, destined to contain certain type of data.

in Java & in many other Programming Languages it's neccessary to declare data type of a variable.

there are other Programming Languages that behave differently.

in Java there's no neccessity to put variable declaration at beginning of a 'method', code's part.

notation (syntax) used in Java is:

  int firstNumber = 3;
  firstNumber = 4;

yes, data type has to be declared only once, for certain code's part.

variable declaration with assignment in one line is called 'definition'.

where 'int' is 'integer data type', it allows for storing numbers from -2147483648 to 2147483647, inclusively.

in Java, integer is 32-bit signed number.

more about 'data types' later.

occassionally, an 'assignment instruction' is called a 'LET instruction'.

Brak komentarzy:

Prześlij komentarz