General Revision Flashcards
(120 cards)
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