2. Sequential execution and program errors Flashcards

1
Q

What are two reasons why programs are divided into classes?

A

By dividing the program into classes, it makes it easier to manage them. Another reason is, that it makes it easier to share the pieces between more than one program (software reuse).

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

What is the first word in the source of a public class?

A

The reserved word ‘public’, which means it can be accessed from anywhere in the running Java environment.

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

What is the general form of a class definition?

A
public class Program {
 ... stuff in here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What aspects of layout matters to the compiler?

A

Java does not care how we lay our code out, as long as we use some white space to separate adjacent symbols, that would otherwise be treated as one symbol if they were joined.

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

What is the basic principle behind the way we indent our programs?

A

The more nested a part of the code is, the more space it has at the start of its lines.

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

What does String[] mean?

A

A list of strings.

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

What is the index of the first command line argument and how is that argument accessed?

A

The first command line argument has the index of 0, and is accessed by calling the list args with the index 0 as args[0]

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

What is the source of errors?

A

When writing the source code for a program, and something went wrong. (Not following the rules of the language).

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

What is the cause of syntactic errors?

A

This is caused when we break the syntax rules of the language. (E.g. We miss out a closing bracket, or insert an extra one, etc.)

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

What is the cause of semantic errors?

A

This is caused when we obey the rules of the syntax, but what we have written, does not making any sense. (E.g. writing public static void main(Text[] args)

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

What are the two kinds of compile time errors?

A

Syntactic errors and semantic errors.

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

Why can the compiler not detect run time errors?

A

Because run time errors are detected and reported by the virtual machine, when the program is run.

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

Why can neither the compiler nor the virtual machine detect logical errors for us?

A

Because as far as Java is concerned, what we’ve wrote is meaningful, but the program just doesn’t do the thing that we wanted it to do.

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

What is the relationship between Java statements being executed sequentially, and byte codes being executed sequentially?

A

The java compiler turns each statement into corresponding byte codes, and the virtual machine executes each collection of byte codes in return.

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

What heading does the main method always have?

A

public static void main(String[] args)

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

Why does the main method have to be public?

A

The program could not be run by the virtual machine if the starting point was not accessible to it.

17
Q

What would be the consequence if the main method was not static?

A

The program would not be able to start if the main method was not allowed to run in the static context.

18
Q

Does the main method return a value?

A

The main method does not return a value.

19
Q

Why is the main method called main?

A

Because it is the main part of the program.

20
Q

What is System?

A

System is a class, that comes as part of Java’s application programming interface (API)

21
Q

What does a statement do?

A

A statement is a command in a programming language, which makes the computer perform a task.

22
Q

Why are simple statements ended with a semi-colon?

A

Because it is a rule of the Java language syntax.

23
Q

What kind of quotes are used for string literals?

A

Double quotes “”

24
Q

How is a string literal ended?

A

String literals must be ended on the same line they are started on.

25
Q

What operator is used for concatenation?

A

+ (plus)