2. Sequential execution and program errors Flashcards
What are two reasons why programs are divided into classes?
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).
What is the first word in the source of a public class?
The reserved word ‘public’, which means it can be accessed from anywhere in the running Java environment.
What is the general form of a class definition?
public class Program { ... stuff in here }
What aspects of layout matters to the compiler?
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.
What is the basic principle behind the way we indent our programs?
The more nested a part of the code is, the more space it has at the start of its lines.
What does String[] mean?
A list of strings.
What is the index of the first command line argument and how is that argument accessed?
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]
What is the source of errors?
When writing the source code for a program, and something went wrong. (Not following the rules of the language).
What is the cause of syntactic errors?
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.)
What is the cause of semantic errors?
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)
What are the two kinds of compile time errors?
Syntactic errors and semantic errors.
Why can the compiler not detect run time errors?
Because run time errors are detected and reported by the virtual machine, when the program is run.
Why can neither the compiler nor the virtual machine detect logical errors for us?
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.
What is the relationship between Java statements being executed sequentially, and byte codes being executed sequentially?
The java compiler turns each statement into corresponding byte codes, and the virtual machine executes each collection of byte codes in return.
What heading does the main method always have?
public static void main(String[] args)