Moment 1 Flashcards

Chapter 3.1 - 3.5 Chapter 2.5.4 , 2.5.6, 2.6 and 2.7

1
Q

What is the procedure for solving a problem?

A
  1. the actions to execute and
  2. the order in which these actions execute

is called an algorithm.

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

What is an important component when writing an algorithm?

A

The order in which the actions executed.

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

Specifying the order in which statements (actions) execute in a program is called?

A

program control

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

What is Pseudocode?

A

Pseudocode is an informal language that helps you develop algorithms without having to worry about the strict details of Java language syntax.

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

What dose Pseudocode help with?

A

Pseudocode does not execute on computers. Rather, it helps you “think out” a program before attempting to write it in a programming language, such as Java.

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

What is sequential execution?

A

Normally, statements in a program are executed one after the other in the order in which they’re written. This process is called sequential execution.

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

What is transfer of control?

A

Various Java statements enable you to specify that the next statement to execute is not necessarily the next one in sequence. This is called transfer of control.

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

Bohm and Jacopini’s work demonstrated that all programs could be written in terms of only three control structures—Which?

A

the sequence structure
the selection structure
the iteration structure.

Reefed to as, in the terminology of the Java Language Specification, “control statements.”

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

What are Activity diagrams?

A

Activity diagrams are composed of symbols, such as action-state symbols (rectangles with their left and right sides replaced with outward arcs), diamonds and small circles. These symbols are connected by transition arrows, which represent the flow of the activity—that is, the order in which the actions should occur.

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

What dose activity diagrams help with?

A

Like pseudocode, activity diagrams help you develop and represent algorithms. Activity diagrams clearly show how control structures operate.

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

activity diagram:

The solid circle at the top of the activity diagram represents?

A

the initial state—the beginning of the workflow before the program performs the modeled actions.

See fig 3.1 on page 123 in book

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

activity diagram:

The solid circle surrounded by a hollow circle at the bottom of the diagram represents?

A

the final state—the end of the workflow after the program performs its actions.

See fig 3.1 on page 123 in book

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

activity diagram:

The arrows represents?

A

The arrows represent transitions, which indicate the order in which the actions represented by the action states occur.

See fig 3.1 on page 123 in book

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

activity diagram:

Figure 3.1 also includes rectangles with the upper-right corners folded over. These are?

A

UML notes (like comments in Java)—explanatory remarks that describe the purpose of symbols in the diagram.

See fig 3.1 on page 123 in book

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

What are Javas three types of selection statements?

A

if statement
if…else statement
switch statement

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

What dose the “if” statement do?

A

The if statement either performs (selects) an action, if a condition is true, or skips it, if the condition is false.

The if statement is a single-selection statement because it selects or ignores a single action (or, as we’ll soon see, a single group of actions).

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

What dose the “if…else” statement do?

A

The if…else statement performs an action if a condition is true and performs a different action if the condition is false.

The if…else statement is called a double-selection statement because it selects between two different actions (or groups of
actions).

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

What dose the “switch” statement do?

A

The switch statement performs one of many different actions, depending on the value of an expression.

The switch statement is called a multiple-selection statement because it selects among many different actions (or groups of actions).

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

What are Javas four iteration statements (also called repetition statements or looping statements)?

A

while,
do…while
for
enhanced for

20
Q

What is the loop-continuation condition?

A

It enable programs to perform statements repeatedly as long as a condition remains true.

21
Q

What does the iteration statements “while” and “for” do?

A

The while and for statements perform the action (or group of actions) in their bodies zero or more times—if the loop-continuation condition is initially false, the action (or group of actions) will not execute.

22
Q

What does the iteration statements “do…while” do?

A

The do…while statement performs the action (or group of actions) in its body one or more times.

23
Q

What are Javas three control structures (called control statements)?

A
sequence statement,
selection statements (three types)
iteration statements (four types)
24
Q

activity diagram:

What dose the diamond symbolize?

A

or decision symbol

it indicates that a decision is to be made.

See fig 3.2 on page 125 in book

25
Q

activity diagram:

The diamond symbolize is accompanied by a?

A

Guard condition, which can be true or false.

26
Q

What does “import java.util.Scanner; // program uses class Scanner” do?

A

an import declaration that helps the compiler locate a class that’s used in this program. It indicates that the program uses the predefined Scanner class (discussed shortly) from the package named java.util. The compiler then ensures that you use the class correctly.

27
Q

What is a variable?

A

A variable is a location in the computer’s memory where a value can be stored for use later in a program.

28
Q

What is integer values

A

whole numbers such as 72, –1127 and 0.

29
Q

What is a prompt?

A

it directs the user to take a specific action.

EX:
KoD: System.out.print(“Enter first integer: “); // prompt
System.out.print displays the message “Enter first integer: “. prompting the user to respond.

30
Q

What are the most common symbols in a flow chart?

A

Oval or Pill Shape - Represents the start or end
Parallelogram - Represents input/output
Rectangle Shape - Represents a process
Diamond Shape - Represents a decision

31
Q

What is a variable?

A

A variable is a named unit of data that is assigned a value. If the value is modified, the name does not change. Variables are used with most programming languages and come in many forms, defined by the script or software programmer.

32
Q

What is a primitive type and what types are there?

A

The Java programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable’s type and name, as you’ve already seen:

int gear = 1;

Doing so tells your program that a field named “gear” exists, holds numerical data, and has an initial value of “1”. A variable’s data type determines the values it may contain, plus the operations that may be performed on it. In addition to int, the Java programming language supports seven other primitive data types.
A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are:

byte:
short
int: 
long:
float:
double:
boolean:
char
33
Q

What rules apply to naming variables?

A

As said before, the name of variables and constants shall not contain the following Swedish characters å, ä, ö.

The name that you choose shall describe the function of the variable (mnemonic names) without being too long. Avoid self-composed abbreviations as it can be difficult for others to understand what you mean.

Do not use the same variable for different tasks in the program: meaning, do not overwrite variables (or constants).

When the name of a variable contains more than one word, use capital letters to distinguish between the different words.

Do not use the so-called “reserved words” in the Java language, even when it is technically possible. For example, don’t name the variable of class “Scanner” as “scanner”.

Do not initialize a variable with a computation. This decreases the readability and the flexibility of the code. See the example below:

// do not do this
int area = base * height;
//do this
// Declaration of variables
int area = 0;
// Computation of variables
area = base * height;

Do not use magic numbers. If the length of your array is, let’s say 3, do not just write “3” in your for loop, use array.length.

34
Q

What is a constant?

A

Java Constant As the name suggests, a constant is an entity in programming that is immutable. In other words, the value that cannot be changed.

35
Q

What is a comment in a Java file?

A

Commenting on your code is very important. You will be surprised how easy it is to forget what you coded, and how difficult is for other people to understand your code. Do not rewrite with a comment the code. But comment on what the code is supposed to do, and explain the logic that your code is following.

Comments shall be made immediately before the code to which it belongs and should be quite concise.

Use // to comment on one line.
Use / * to comment on multiple lines * /
Note that / ** ... * / is a special comment used for class and method head-comments.
36
Q

What does allocation mean?

A

Memory allocation in java refers to the process where the computer programs and services are allocated dedicated to virtual memory spaces. The Java Virtual Machine divides the memory into Stack and Heap Memory. For Java Virtual Machine, executing an application in its maximum potential can happen from stack and heap memory.

37
Q

How to convert a floating-point number to an integer?

A

you can convert a float to an int by simply down-casting it e.g. “(int) 4.0f” will give you integer 4.

38
Q

What value dose the Primitive Data Types “byte” take?

A

The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable’s range is limited can serve as a form of documentation.

39
Q

What value dose the Primitive Data Types “short” take?

A

The short data type is a 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.

40
Q

What value dose the Primitive Data Types “int:” take?

A

By default, the int data type is a 32-bit signed two’s complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.

41
Q

What value dose the Primitive Data Types “long:” take?

A

The long data type is a 64-bit two’s complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.

42
Q

What value dose the Primitive Data Types “float:” take?

A

The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.

43
Q

What value dose the Primitive Data Types “double:” take?

A

The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

44
Q

What value dose the Primitive Data Types “boolean:” take?

A

The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its “size” isn’t something that’s precisely defined.

45
Q

What value dose the Primitive Data Types “char:” take?

A

The char data type is a single 16-bit Unicode character. It has a minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (or 65,535 inclusive).