General Revision Flashcards

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
Q

Write out De Morgan’s rules in full

A

!(A && B) is equivalent to !A || !B
!(A || B) is equivalent to !A && !B
(can be extended to three operands)

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

What is a ‘Mutator Method’?

A

A method that sets or modifies an object’s instance variables.

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

What is an ‘Accessor Method’?

A

A method that gets or retrieves the value of an instance variable.

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

How does one achieve Encapsulation in Java?

A

Declare the variables of a class as private.

Provide public setter and getter methods to modify and view the variables values.

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

What’s the difference between an instance variable and a local variable?

A

Instance variables are declared inside a class but not within a method.

Local variables are declared within a method. (Must be initialised before use).

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

What is the term ‘String’ shorthand for?

A

String of characters

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

What does Integer.valueOf command do?

A

Converts a string to an integer.

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

What is meant by ‘The state of an object’?

A

The value of the object’s internal variables at any given point in time.

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

What does this tell the compiler?

type[ ] arrayName

A

arrayName will refer to an array that contains cells of type

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

What’s the difference between score.length and score.length() ?

A

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.

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

In terms of an ArrayList (Java) what is the difference between capacity and size?

A

Capacity: total number of cells.
Size: number of cells that have data in them,.

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

How would you put an int into an ArrayList?

A
Put the int inside of an Integer object: (for ArrayList data:
data.add( new Integer(1) );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What type of data does an InputStream handle?

A

byte data

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

What type of data does an OutputStream handle?

A

byte data

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

What is the ancestor class of streams that do character-oriented output?

A

Writer

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

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).

A

FileWriter

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

What is the disk file format for characters that is intended to work for all human languages?

A

UTF

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

What is a buffer?

A

A section of main memory used as a work area for input or output operations.

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

Does the println() method of PrintWriter throw exceptions?

A

No - no methods of PrintWriter throw exceptions.

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

Which operation is usually more reliable: input or output?

A

Output.

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

What is the ancestor class of all character-oriented input streams?

A

Reader

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

Can a FileReader object be constructed that is not connected to any file?

A

No—the constructor must specify a file.

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

Should FileReader be used to read a Java bytecode (*.class) file?

A

No—the bytes in bytecode files are not intended to be interpreted as characters.

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

What class does readLine() belong to?

A

BufferedReader

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

What data type does readLine() return?

A

String

50
Q

What happens if readLine() encounters an error?

A

It throws an IOException

51
Q

What is the ancestor class of all character-oriented input streams?

A

Reader

52
Q

What stream type provides input from a disk file?

A

FileReader

53
Q

What value does readLine() return upon encountering end-of-file?

A

null

54
Q

What makes an argument deductively valid?

A

If it is impossible for the premises to be true and the conclusion false. It is invalid otherwise.

55
Q

What is a Tautology?

A

A sentence that must be true, as a matter of logic.

56
Q

In logical terms, what is a contradiction?

A

A sentence that must be false, as a matter of logic.

57
Q

What is a contingent sentence?

A

A sentence that is neither a tautology or a contradiction.

58
Q

What makes two sentences logically equivalent?

A

If they necessarily have the same truth value.

59
Q

In logical terms, what makes a set of sentences consistent?

A

If it is logically possible for the all the members of the set to be true at the same time.

60
Q

What are the three major activities of a computer system?

A
  1. input data
  2. process data
  3. output processing results
61
Q

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.

A

Main Memory

62
Q

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.

A

Secondary Memory

63
Q

What is another term for main memory?

A

RAM

64
Q

Is anything permanent kept in main memory?

A

No

65
Q

In terms of the computer’s processor, what is meant by ‘Machine Operation’?

A

Each tiny electronic operation it performs

66
Q

Which is faster; an interpreter or a compiler?

A

Interpreter

67
Q

What is a Java Runtime Environment?

A

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
Q

In object oriented programming what is the difference between an object and a class?

A

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
Q

In object oriented programming, what is meant by polymorphism?

A

Different objects can respond to the same message in different ways.

70
Q

When referring to a class in Object Oriented Programming, what does inheritance refer to?

A

A class can inherit some or all of its structure and behaviour from another class

71
Q

What is meant by the term ‘abstract class’?

A

An abstract class is one that is not used to construct objects, but only as a basis for making subclasses.

72
Q

If you declare a class but do not declare a superclass, what is the default Java superclass?

A

Object (the most abstract class of all)

73
Q

Define what is meant by ‘variable’ in computer programming?

A

A named location in main memory which uses a particular data type to hold a value.

74
Q

How many bits are there in a byte?

A

8

75
Q

What’s the minimum and maximum value of an int?

A

-2E31 and a maximum value of 2E31(-1)

76
Q

How many bits in an integer?

A

32

77
Q

How many bits in a double?

A

64

78
Q

How many bits in a char?

A

16

79
Q

What’s the default value of a String?

A

null

80
Q

What are the two data types in Java?

A

Primitives and Objects

81
Q

How many bits are in a String?

A

16

82
Q

What does it mean when we say that String objects are immutable?

A

A String’s behaviours do not modify that String’s attributes. Rather, they return a new string.

83
Q

In terms of object oriented programming, what is another name for a method?

A

A behaviour.

84
Q

What is meant by concurrent processing?

A

More than one process being executed at the same time.

85
Q

Java is considered a ‘pass by value’ language. Explain what is meant by this.

A

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
Q

What does the concat() method do?

A

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
Q

What does the trim() method of a String object do?

A

Creates a new String object that is the same as the original but any leading or trailing whitespace is removed.

88
Q

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));

A

Returns a single character at the specified index.
Value returned is a char.

Example prints e

89
Q

What does this program print?

String source = “applecart”;
String sub = source.substring(6);
System.out.println( sub );
System.out.println( source );

A

art
applecart
(String source is not changed; sub is a new object)

90
Q

What does this program print?

String snake = “rattlesnake”;
String snakeTwo = snake.substring(11);
System.out.println(snakeTwo);

A

empty character

91
Q

Can an object reference variable exist that without referring to an object?

A

Yes, a reference variable can be declared without initialization:
String myString;
Also a reference can be set to null

92
Q

Can an object exist without an object reference variable that refers to it?

A

Yes (temporary object)

93
Q

What type of data does the startsWith() method return?

A

Boolean

94
Q

In terms of invoking a method, what is meant by the term ‘argument’?

A

The actual value that is supplied when the method is invoked.

95
Q

Are constructors inherited by a class’s subclass?

A

No

96
Q

Can a constructor return a value?

A

No

97
Q

What does a method’s signature consist of?

A

Method’s name, plus number, types and order of its formal parameters.

98
Q

How is it possible to have two behaviors with exactly the same name within a class description?

A

Methods have signatures. If the signature of the method is different, the method name can be the same.

99
Q

What is meant by a ‘class attribute’ in Java?

A
Variables within a class:
public class Main {
  int x = 5;
  int y = 3;
}
x and y are class attributes. (also known as fields)
100
Q

What does this statement do:

int[] data = new int[10];

A

Creates an array of 10 ints, puts a zero into each cell, and puts a reference to that object in data.

101
Q

Is it possible for a 2D array to have a different number of cells in each row?

A

Yes

102
Q

What does this declaration mean:

int[][] myArray ;

A

myArray is expected to hold a reference to a 2D array of int. Without any further initialization, myArray starts out holding null.

103
Q

What does this declaration mean:

int[][] myArray = new int[3][5] ;

A

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
Q

How is the length of a 2D array defined?

A

The number of rows it has.

105
Q

What is a handy term to remember when thinking of ‘ == ‘ ?

A

Alias detector (if false, objects either side are not in same area of memory)

106
Q

What conditions must be met for Array.equals() to return true?

A

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
Q

May an ArrayList element contain int or double data?

A

No; the elements must be object references. You cannot use primitive data. (You could use to store integer object references.

108
Q

Which method is used to find the current size of an ArrayList?

A

size()

109
Q

Does the value ‘null’ in an ArrayList cell count as data?

A

Yes

110
Q

What does the indexOf(Object element) of an ArrayList do?

A

Search for the first occurrence of

element, testing for equality using the equals(Object) method of element.

111
Q

What package does Java use to move data into and out from a computer program?

A

utility package

112
Q

What are the three fundamental data streams in Java?

A

System.in - input
System.out - output
System.err - error messages

113
Q

In terms of computer programming, what is meant by ‘casting’?

A

Turning one fundamental data value into another type.

114
Q

What type of input / output data do InputStream and OutputStream handle?

A

Primitive data types or raw bytes

115
Q

What’s the difference between a text file and a binary file?

A

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
Q

Which class is the root class of ‘Exception’ class?

A

‘Throwable’

117
Q

What’s the difference between dynamic and static scope?

A

Static scope refers to how the program is written.

Dynamic scope refers to how the program executes.

118
Q

Can OutputStreamWriter be used to write to an existing text file?

A

Yes

119
Q

Can PrintWriter be used to write to an existing text file?q

A

Not on its own; it must be used with FileWriter or OutputStreamWriter

120
Q

What is the technical term for the basic computer model?

A

Architecture