3.1.1.2 Programming Concepts. Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define a variable declaration.

A

To define (create) a variable you must specify the type and assign it a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define the syntax for variable declaration?

A

type variable = value;

String father = “Milk”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define a constant.

A

A constant is a variable whose cannot change once it has been assigned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define the syntax for a constant.

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define assignment.

A

An assignment statement designates a value for a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define the syntax for assignment.

A

variable = expression;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define iteration.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Give examples for iteration.

A

There are multiple methods, one of the most common one would be a for loop:

for(int i = 0; i < value; i++){

};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define Selection.

A

Selection statements are known as decision making statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give examples for selection.

A
  • If statements.
  • Switch statements.
  • If else statement.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define a subroutine.

A

A sequence of program instructions that performs a specific task, packaged as a unit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define definite iteration.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define indefinite iteration.

A

Indefinite iteration repeatedly executes a section of code until a condition is or is no longer met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define nested iteration.

A

Using two forms of iteration, one within the other. An example would be:

for(…..){

 for(.....){

  } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is it important to use meaningful identifier names in a program?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly