3.1.1.2 Programming Concepts. Flashcards
Define a variable declaration.
To define (create) a variable you must specify the type and assign it a value.
Define the syntax for variable declaration?
type variable = value;
↓
String father = “Milk”;
Define a constant.
A constant is a variable whose cannot change once it has been assigned.
Define the syntax for a constant.
Keyword ‘final’.
e.g.
final int num = 1;
- As a rule, write constants in capital letters to differentiate them from normal variables.
- If you try and change the constant in the program, javac sends an error message, this is because you can only assign a value to a constant once.
Define assignment.
An assignment statement designates a value for a variable.
Define the syntax for assignment.
variable = expression;
Define iteration.
An iterator is an object that can be used to loop through collections, like ArrayList and HashSet.e
It is called an ‘iterator’ because ‘iterating’ is the technical term for looping through.
To use, you must import the java.util package.
Give examples for iteration.
There are multiple methods, one of the most common one would be a for loop:
for(int i = 0; i < value; i++){
};
Define Selection.
Selection statements are known as decision making statements.
Give examples for selection.
- If statements.
- Switch statements.
- If else statement.
Define a subroutine.
A sequence of program instructions that performs a specific task, packaged as a unit.
Define definite iteration.
When a program needs to iterate a set a number of times, this is knows as definite iteration and makes use of a FOR loop. A for loop uses an extra variable called a loop counter that keeps track of the number of times the loop has been run.
Define indefinite iteration.
Indefinite iteration repeatedly executes a section of code until a condition is or is no longer met.
Define nested iteration.
Using two forms of iteration, one within the other. An example would be:
for(…..){
for(.....){ } }
Why is it important to use meaningful identifier names in a program?
Makes it easier for the next person to work on the code and to understand it.
These names are called identifiers and follow certain rules:
- They can contain letters and numbers but must start with a letter.
- They must contain at least one letter (at the start of the name).
- They must not contain special characters or punctuation however, an underscore can be used.
- Spaces are not allowed.
- They will normally contain lower case letters. however, upper case letters can be used if a variable name compromises more than one word joined together.
- The name should be meaningful - it should represent the value it is holding.