General Revision Flashcards
What’s the difference between the do and while statement?
Thedostatement performs a testaftereach execution of the loop body.
Is the do statement a necessary feature in Java?
No–everything it does could be done with a while.
What are the branching statements in a programming language?
Statements like if that make choices.
What’s the longhand of x += y
x = x + y
What’s the longhand of x-=y
x = x - y
Briefly describe what Hardware Control Structures are.
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.
Briefly describe what Software Control Structures are.
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.
Explain the difference between a method declaration and a method invocation.
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.
Explain the difference between a parameter and an argument.
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)..
Describe the basics of a constructor.
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.
What is meant by ‘time slicing’?
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.
What is meant by ‘Round-Robin Scheduling?’
In round-robin scheduling, each thread is given an equal slice of time, in a first-come–first-served order.
what does the sleep() method do?
The sleep() method removes a thread from the CPU for a determinate length of time, giving other threads a chance to run.
What does the setpriority() method do?
The setPriority() method sets a thread’s priority. Higher-priority threads have more and longer access to the CPU.
Threads are asynchronous. Explain what is meant by this.
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.
Define what is meant by ‘Formal Parameter’
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) { }
Define what is meant by ‘Actual Parameter’
The actual value that is passed into the method (or constructor) by a caller. Often called ‘arguments’.
Can a formal parameter be used to store the state of an object?
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.
What is a ‘local variable’?
A variable that is declared inside of the body of a method.
Is the scope of a local variable always the entire body of a method?
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.
Is the return type part of the signature of a method?
No
Say that a class has these two methods:
public void changeInterestRate( double newRate ) { … }
public void changeInterestRate( int newRate ) { … }
Do these methods have unique signatures?
Yes. The names of the formal parameters do not have to be unique.
What is wrong with this expression:
!speed > 2000 && memory > 512
(consider speed to be of data type int)
Speed is an integer and ! only applies to boolean values.
Should be written !(speed > 2000 && memory > 512)
What is !!A equivalent to?
A
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)
What is a ‘Mutator Method’?
A method that sets or modifies an object’s instance variables.
What is an ‘Accessor Method’?
A method that gets or retrieves the value of an instance variable.
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.
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).
What is the term ‘String’ shorthand for?
String of characters
What does Integer.valueOf command do?
Converts a string to an integer.
What is meant by ‘The state of an object’?
The value of the object’s internal variables at any given point in time.
What does this tell the compiler?
type[ ] arrayName
arrayName will refer to an array that contains cells of type
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.
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,.
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) );
What type of data does an InputStream handle?
byte data
What type of data does an OutputStream handle?
byte data
What is the ancestor class of streams that do character-oriented output?
Writer
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
What is the disk file format for characters that is intended to work for all human languages?
UTF
What is a buffer?
A section of main memory used as a work area for input or output operations.
Does the println() method of PrintWriter throw exceptions?
No - no methods of PrintWriter throw exceptions.
Which operation is usually more reliable: input or output?
Output.
What is the ancestor class of all character-oriented input streams?
Reader
Can a FileReader object be constructed that is not connected to any file?
No—the constructor must specify a file.
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.
What class does readLine() belong to?
BufferedReader