2221 Study Materials
Aliasing
A circumstance where two or more variables refer to the same object.
mutable type
A compound data type whose elements can be assigned new values.
immutable type
A data value which cannot be modified. Assignments to elements or slices (sub-parts) of immutable values cause a runtime error.
requires
A method precondition
postcondition
A statement of what must be true at the end of the execution of the code.
primitive type
A variable data type in which the variable's value is of the appropriate size and format for its type: a number, a character, or a boolean value.
Assume the precondition is true when the method is called.
According to the "contract" in design-by-contract, the implementer of a method is permitted to:
NaturalNumber
After execution of the following code, what is the declared type (static type) of nCopy? Natural Number n = new NaturalNumber1L(); Natural Number nCopy = new NaturalNumber2(n);
NaturalNumber2
After execution of the following code, what is the declared type (static type) of nCopy? Natural Number n = new NaturalNumber1L(); Natural Number nCopy = new NaturalNumber2(n);
B.)
Assume n is an int variable. Which Java expression is true exactly when n is an odd number, i.e., not divisible by 2, and should be used to check for this situation? A.) n % 2 == 1 B.) n % 2 != 0 C.) Both A and B D.) Neither A and B
A.
Consider the following method contract and client code: /** * Adds n to this. *@updates this *@ensures this = #this + n */ public void add(NaturalNumber n){...} ... NaturalNumber num = new NaturalNumber2(10); num.add(num); What is the value of num after the method call? A. Cannot tell from the information provided. B. num = 0 C. num = 10 D. num = 20
a formal parameter
Consider the following method signature: private static int examScore(int studentNumber) {} Here, studentNumber is called:
Interface
Description of the boundary between a system and everything else
Debugging
Finding and fixing problems in your algorithm or program.
Clears
For a method formal parameter, which parameter mode is the default when no parameter mode is specified in the method's contract?
extends
For two classes or interfaces, this relation causes B (given B extends A) to inherit all methods of A, but not the constructors
D.)
Given the following code and assuming that all necessary imports and the rest of the class are provided correctly, which of the statements below is true? SimpleWriter out = new SimpleWriter1L(); NaturalNumber n1 = new NaturalNumber1L(6); NaturalNumber n2 = new NaturalNumber1L(4); NaturalNumber n3 = new NaturalNumber1L(11); A.) The code will result in a run-time error. B.) The code will output "yes". C.) The code will output "no". D.) The code will not compile.
C.)
Given the following code and assuming that all necessary imports and the rest of the class are provided correctly, which of the statements below is true? SimpleWriter out = new SimpleWriter1l(); NaturalNumber n1 = new NaturalNumber1L(5); NaturalNumber n2 = n1; n2.decrement(); out.println("n2=" + n1 + ",n2 = " + n2); A.) The code will not compile. B.) The code will output "n1=5, n2=4". C.) The code will output "n1=4, n2=4". A.) The code will result in a run-time error.
The client code that calls the method
In design-by-contract, the code responsible for making sure the precondition (requires clause) is true when a method is called is:
none of these choices
In design-by-contract, when the precondition(requires clause) of a method is not satisfied the implementer of a method is obligated to:
B
In testing, which one of the following statements is true? A. Testing is capable of proving that a method body is correct B. Failing test cases allow testers to immediately figure out the source of the failure C. Test cases can indicate a method has problems, but not necessarily what they are D. Testing usually takes up only a small portion of software development time
Pass-by-value
Java uses what type of parameter passing?
aliases
Multiple variables that contain references to the same object.
Method Overriding
Providing a new implementation for an inherited method
method overriding
Providing a new implementation for an inherited method
Implements
Relation between a class and an interface in Java
clears
Resets to zero
Parameter Modes
Restores, Clears, Updates, Replaces
Testing
Showing that code is defective by executing it
implementer
Someone viewing a system from the inside
be legal in Java (though flagged by Checkstyle)
Suppose the method from question 1.2 is called in the following statement: int k = examScore(42); This call would certainly::
<img src="brutus.jpg" />
Suppose you want to display the image file brutus.jpg in a browser, along with other content as organized in the HTML file index.html. Both these files are in the same folder/directory. Which HTML code fragment in index.html will produce the desired result? (Note that a well-formed HTML document such as the one you were to create for project #1 is an XML document.)
oneToThree = 1.0 + 2.0 * r.nextDouble();
Suppose you want to set the double variable oneToThree to a random real number uniformly distributed in the interval [1.0, 3.0). You have made the following declaration: Random r = new Random1L(); noting that r.nextDouble() returns a random real number uniformly distributed in the interval [0.0, 1.0). Which statement will set oneToThree to the desired result?
method overloading
The ability to define two or more different methods with the same name but different method signatures.
B.
The interval-halving technique can be used to compute results for problems like guessing numbers and finding roots because: A. In Java, division by two throws away the remainder. B. The answer to the question you can ask to get information about the mid-point of the interval allows you to eliminate (as possible results) all points on one side of the mid-point. C. All numbers involved in the computation are non-negative. D. The function you are evaluating over the interval has no more than two maximum or minimum values in that interval.
Extends
The name of the inheritance relation in Java
Statement
The smallest element of a programming language which expresses an action to be carried out.
Object Type
The type of a variable used by Java to decide which method body to use in the presence of overriding
Reference type
Type of variable representing a memory address
D.
What are the values of array and str after the call to bar? private static void bar(String [] a, String s) { s = a[0] + "io"; a[0] = s; } ... String [] array = {"Oh"}; String str = "USA"; bar(array, str); A. array = {"Oh"}, str = "USA" B. array = {"Oh"}, str = "Ohio" C. array = {"Ohio"}, str = "Ohio" D. array = {"Ohio"}, str = "USA"
C.
What are the values of num1 and num2 after the call to foo? private static void foo (NaturalNumber n1, NaturalNumber n2) { n2 = n1.divide(n2); } ... NaturalNumber num1 = new NaturalNumber2(31); NaturalNumber num1 = new NaturalNumber2(4); foo(num1, num2); A. num1 = 31, num2 = 4 B. num1 = 31, num2 = 3 C. num1 = 7, num2 = 4 D. num1 = 7, num2 = 3
Unpredicted error
What happens if the client violates precondition of a method
A method appears multiple times within different classes related by inheritance, each time with the same argument types and number.
What is an overridden method?
Recursion
When a function calls itself.
A.)
Which statement is true when testing a method? A.) A single test case can show the presence of a defect in the method body. B.) Very thorough testing can prove the correctness of the method body. C.) Testing is generally considered an expensive waste of time in industry. D.) A single test case can show the absence of defects in the method body if it produces correct results for the particular choice of inputs in that test case.
C
With regards to testing best practices for unit testing methods, which of the following types of tests are not usually performed? A. Tests using easy or common values B. Tests that test the limits of possible values C. Tests with values that violate preconditions to check for error D. Tests that use values that might be difficult for the method under test
precondition
a condition that must be fulfilled before other things can happen or be done.
reference type
a data type that contains a pointer to the memory location of an object
array
a group of similar variables of the same type
ensures
a method postcondition
Design-by-contract
a particular approach that uses the documentation only to capture the design but also to encourage interaction among developers
formal parameter
a variable in a method definition; it is initialized with an actual parameter value when the method is called
restores
actions done to n must be undone so n is the same at start and finish
Expression
can be evaluated to produce a value
superclass/base class/parent class
class which has been extended by another class
replaces
does not use the original value of n (Copy From)
statement3
double x = rnd.nextDouble();
debugging
finding and repairing a defect in code
statement
if(x < 0.5){}
subinterface/derived interface/child interface
inherits all method declarations of the interface it inherits
information hiding
intentionally leaving out internal details of a system
Argument or Actual Parameter
provided when calling a method
implements
provides bodies for everything in the given interface
Abstraction
providing a valid cover story for the behavior of a system
expression3
ptsInInterval + 1;
expression
ptsInInterval < n
statement2
ptsInInterval = ptsInInterval + 1;
expression2
rnd.nextDouble();
client
someone viewing a system from the outside
updates
takes the original value of n and makes a new value
Polymorphism
the object reference is used to refer to objects with different forms
declared type
type of variable used by the java compiler to determine how the variable can be used
Declared type/Static type
variables are not defined before use
Object type/Dynamic type
variables must be defined before they are used
statement4
while(ptsInInterval < n){}
expression4
x < 0.5