General Revision Flashcards

(120 cards)

1
Q

What’s the difference between the do and while statement?

A

Thedostatement performs a testaftereach execution of the loop body.

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

Is the do statement a necessary feature in Java?

A

No–everything it does could be done with a while.

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

What are the branching statements in a programming language?

A

Statements like if that make choices.

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

What’s the longhand of x += y

A

x = x + y

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

What’s the longhand of x-=y

A

x = x - y

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

Briefly describe what Hardware Control Structures are.

A

The hardware control structures are the set of instructions that determine the address of the next instruction to be executed and entered into the Instruction Register.

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

Briefly describe what Software Control Structures are.

A

Software programs are general problem solving representations that can be translated into hardware programs. Software programs are comprised of sets of instructions, that include arithmetic instructions, logical instructions, read / write instructions, and control instructions.

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

Explain the difference between a method declaration and a method invocation.

A

Method declaration defines the method by specifying its name, qualifiers, return type, formal parameters and its algorithm, thereby associating a name with a segment of executable code.
Invoking a method involves writing a method call statement.
Calls or uses a defined method.

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

Explain the difference between a parameter and an argument.

A

Parameter is a value that is defined in a method, eg: myMethod(int parameter)..

Argument refers to actual value that is supplied when the method is invoked; eg example.myMethod(5)..

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

Describe the basics of a constructor.

A

A constructor is a method that is invoked when an object is created. If a class does not contain a constructor method, the Java compiler supplies a default constructor.

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

What is meant by ‘time slicing’?

A

Time slicing is the technique whereby several threads can share a single CPU over a given time period. Each thread is given a small slice of the CPU’s time under the control of some kind of scheduling algorithm.

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

What is meant by ‘Round-Robin Scheduling?’

A

In round-robin scheduling, each thread is given an equal slice of time, in a first-come–first-served order.

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

what does the sleep() method do?

A

The sleep() method removes a thread from the CPU for a determinate length of time, giving other threads a chance to run.

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

What does the setpriority() method do?

A

The setPriority() method sets a thread’s priority. Higher-priority threads have more and longer access to the CPU.

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

Threads are asynchronous. Explain what is meant by this.

A

Threads are asynchronous. Their timing and duration on the CPU are highly sporadic and unpredictable. In designing threaded programs, you must be careful not to base your algorithm on any assumptions about the threads’ timing.

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

Define what is meant by ‘Formal Parameter’

A
The identifier used in a method to stand for the value that is passed into the method (or constructor) by a caller.
(Occurs in definition of method)
Eg setAge(int age) {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Define what is meant by ‘Actual Parameter’

A

The actual value that is passed into the method (or constructor) by a caller. Often called ‘arguments’.

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

Can a formal parameter be used to store the state of an object?

A

No, formal parameters are only bound to an actual value for as long as their method is active. When a method returns to its caller the values are lost.

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

What is a ‘local variable’?

A

A variable that is declared inside of the body of a method.

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

Is the scope of a local variable always the entire body of a method?

A

No — the scope starts where the variable was declared and continues to the end of its block.
Sometimes a local variable is declared in the middle of a block, close to the
statement which first uses it.

Often, local variables are declared at the beginning of a block so that their scope is the
entire block. But this is not a requirement of syntax.

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

Is the return type part of the signature of a method?

A

No

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

Say that a class has these two methods:

public void changeInterestRate( double newRate ) { … }
public void changeInterestRate( int newRate ) { … }
Do these methods have unique signatures?

A

Yes. The names of the formal parameters do not have to be unique.

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

What is wrong with this expression:
!speed > 2000 && memory > 512
(consider speed to be of data type int)

A

Speed is an integer and ! only applies to boolean values.

Should be written !(speed > 2000 && memory > 512)

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

What is !!A equivalent to?

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Write out De Morgan's rules in full
!(A && B) is equivalent to !A || !B !(A || B) is equivalent to !A && !B (can be extended to three operands)
26
What is a 'Mutator Method'?
A method that sets or modifies an object's instance variables.
27
What is an 'Accessor Method'?
A method that gets or retrieves the value of an instance variable.
28
How does one achieve Encapsulation in Java?
Declare the variables of a class as private. Provide public setter and getter methods to modify and view the variables values.
29
What's the difference between an instance variable and a local variable?
Instance variables are declared inside a class but not within a method. Local variables are declared within a method. (Must be initialised before use).
30
What is the term 'String' shorthand for?
String of characters
31
What does Integer.valueOf command do?
Converts a string to an integer.
32
What is meant by 'The state of an object'?
The value of the object's internal variables at any given point in time.
33
What does this tell the compiler? | type[ ] arrayName
arrayName will refer to an array that contains cells of type
34
What's the difference between score.length and score.length() ?
score.length is used to determine the length of the array referenced by score, score.length() is used to determine how long the String reference is.
35
In terms of an ArrayList (Java) what is the difference between capacity and size?
Capacity: total number of cells. Size: number of cells that have data in them,.
36
How would you put an int into an ArrayList?
``` Put the int inside of an Integer object: (for ArrayList data: data.add( new Integer(1) ); ```
37
What type of data does an InputStream handle?
byte data
38
What type of data does an OutputStream handle?
byte data
39
What is the ancestor class of streams that do character-oriented output?
Writer
40
What is the class that translates characters from the internal form (used by a Java program) to the external form (used by a disk file).
FileWriter
41
What is the disk file format for characters that is intended to work for all human languages?
UTF
42
What is a buffer?
A section of main memory used as a work area for input or output operations.
43
Does the println() method of PrintWriter throw exceptions?
No - no methods of PrintWriter throw exceptions.
44
Which operation is usually more reliable: input or output?
Output.
45
What is the ancestor class of all character-oriented input streams?
Reader
46
Can a FileReader object be constructed that is not connected to any file?
No—the constructor must specify a file.
47
Should FileReader be used to read a Java bytecode (*.class) file?
No—the bytes in bytecode files are not intended to be interpreted as characters.
48
What class does readLine() belong to?
BufferedReader
49
What data type does readLine() return?
String
50
What happens if readLine() encounters an error?
It throws an IOException
51
What is the ancestor class of all character-oriented input streams?
Reader
52
What stream type provides input from a disk file?
FileReader
53
What value does readLine() return upon encountering end-of-file?
null
54
What makes an argument deductively valid?
If it is impossible for the premises to be true and the conclusion false. It is invalid otherwise.
55
What is a Tautology?
A sentence that must be true, as a matter of logic.
56
In logical terms, what is a contradiction?
A sentence that must be false, as a matter of logic.
57
What is a contingent sentence?
A sentence that is neither a tautology or a contradiction.
58
What makes two sentences logically equivalent?
If they necessarily have the same truth value.
59
In logical terms, what makes a set of sentences consistent?
If it is logically possible for the all the members of the set to be true at the same time.
60
What are the three major activities of a computer system?
1. input data 2. process data 3. output processing results
61
What is this describing: closely connected to the processor. stored data are quickly and easily changed. holds the programs and data that the processor is actively working with. interacts with the processor millions of times per second. needs constant electric power to keep its information.
Main Memory
62
What is this describing: connected to main memory through the bus and a controller. stored data are easily changed, but changes are slow compared to main memory. used for long-term storage of programs and data. before data and programs can be used, they must be copied from here. does not need electric power to keep its information.
Secondary Memory
63
What is another term for main memory?
RAM
64
Is anything permanent kept in main memory?
No
65
In terms of the computer's processor, what is meant by 'Machine Operation'?
Each tiny electronic operation it performs
66
Which is faster; an interpreter or a compiler?
Interpreter
67
What is a Java Runtime Environment?
A software layer that runs on top of a computer's operating system software and provides the class libraries and other resources that a specific Java program needs to run.
68
In object oriented programming what is the difference between an object and a class?
An object is a specific 'thing'; eg. a particular car, invoice or receipt. We define the general description, attributes and behaviours of a general 'thing' and that becomes the class.
69
In object oriented programming, what is meant by polymorphism?
Different objects can respond to the same message in different ways.
70
When referring to a class in Object Oriented Programming, what does inheritance refer to?
A class can inherit some or all of its structure and behaviour from another class
71
What is meant by the term 'abstract class'?
An abstract class is one that is not used to construct objects, but only as a basis for making subclasses.
72
If you declare a class but do not declare a superclass, what is the default Java superclass?
Object (the most abstract class of all)
73
Define what is meant by 'variable' in computer programming?
A named location in main memory which uses a particular data type to hold a value.
74
How many bits are there in a byte?
8
75
What's the minimum and maximum value of an int?
-2E31 and a maximum value of 2E31(-1)
76
How many bits in an integer?
32
77
How many bits in a double?
64
78
How many bits in a char?
16
79
What's the default value of a String?
null
80
What are the two data types in Java?
Primitives and Objects
81
How many bits are in a String?
16
82
What does it mean when we say that String objects are immutable?
A String's behaviours do not modify that String's attributes. Rather, they return a new string.
83
In terms of object oriented programming, what is another name for a method?
A behaviour.
84
What is meant by concurrent processing?
More than one process being executed at the same time.
85
Java is considered a 'pass by value' language. Explain what is meant by this.
If you pass a value of a primitive type into a method, it is only the value that arrives, not a reference to the variable. Even if you use the same variable name inside the method, changes to the value will not be reflected outside the method.
86
What does the concat() method do?
Performs String concatenation. String first = "Red " ; String last = "Rose" ; String name = first.concat( last ); (new String "Red Rose" created) Could also be done with +
87
What does the trim() method of a String object do?
Creates a new String object that is the same as the original but any leading or trailing whitespace is removed.
88
What does the charAt() method of a String do? What type of value does it return? Eg: String snake = "rattlesnake"; System.out.println(snake.charAt(5));
Returns a single character at the specified index. Value returned is a char. Example prints e
89
What does this program print? String source = "applecart"; String sub = source.substring(6); System.out.println( sub ); System.out.println( source );
art applecart (String source is not changed; sub is a new object)
90
What does this program print? String snake = "rattlesnake"; String snakeTwo = snake.substring(11); System.out.println(snakeTwo);
empty character
91
Can an object reference variable exist that without referring to an object?
Yes, a reference variable can be declared without initialization: String myString; Also a reference can be set to null
92
Can an object exist without an object reference variable that refers to it?
Yes (temporary object)
93
What type of data does the startsWith() method return?
Boolean
94
In terms of invoking a method, what is meant by the term 'argument'?
The actual value that is supplied when the method is invoked.
95
Are constructors inherited by a class's subclass?
No
96
Can a constructor return a value?
No
97
What does a method's signature consist of?
Method's name, plus number, types and order of its formal parameters.
98
How is it possible to have two behaviors with exactly the same name within a class description?
Methods have signatures. If the signature of the method is different, the method name can be the same.
99
What is meant by a 'class attribute' in Java?
``` Variables within a class: public class Main { int x = 5; int y = 3; } x and y are class attributes. (also known as fields) ```
100
What does this statement do: int[] data = new int[10];
Creates an array of 10 ints, puts a zero into each cell, and puts a reference to that object in data.
101
Is it possible for a 2D array to have a different number of cells in each row?
Yes
102
What does this declaration mean: | int[][] myArray ;
myArray is expected to hold a reference to a 2D array of int. Without any further initialization, myArray starts out holding null.
103
What does this declaration mean: | int[][] myArray = new int[3][5] ;
myArray can hold a reference to a 2D array of int, creates an array object of 3 rows and 5 columns, and puts the reference in myArray. All the cells of the array are initialized to zero.
104
How is the length of a 2D array defined?
The number of rows it has.
105
What is a handy term to remember when thinking of ' == ' ?
Alias detector (if false, objects either side are not in same area of memory)
106
What conditions must be met for Array.equals() to return true?
Two arrays are equal if they are the same length, and contain the same elements in the same order. Both arrays must be of the same type.
107
May an ArrayList element contain int or double data?
No; the elements must be object references. You cannot use primitive data. (You could use to store integer object references.
108
Which method is used to find the current size of an ArrayList?
size()
109
Does the value 'null' in an ArrayList cell count as data?
Yes
110
What does the indexOf(Object element) of an ArrayList do?
Search for the first occurrence of | element, testing for equality using the equals(Object) method of element.
111
What package does Java use to move data into and out from a computer program?
utility package
112
What are the three fundamental data streams in Java?
System.in - input System.out - output System.err - error messages
113
In terms of computer programming, what is meant by 'casting'?
Turning one fundamental data value into another type.
114
What type of input / output data do InputStream and OutputStream handle?
Primitive data types or raw bytes
115
What's the difference between a text file and a binary file?
A text file stores a sequence of characters and is the type of file created by standard text editors like NotePad and WordPad on a Windows computer or SimpleText on a Macintosh. A binary file has a more general format that can store numbers and other data the way they are stored in the computer
116
Which class is the root class of 'Exception' class?
'Throwable'
117
What's the difference between dynamic and static scope?
Static scope refers to how the program is written. | Dynamic scope refers to how the program executes.
118
Can OutputStreamWriter be used to write to an existing text file?
Yes
119
Can PrintWriter be used to write to an existing text file?q
Not on its own; it must be used with FileWriter or OutputStreamWriter
120
What is the technical term for the basic computer model?
Architecture