1/95
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
The correct syntax for the "main" method signature is:
a. private static void main(String[] args)
b. public static String main(String[] args)
c. public static void main(String[] args)
d. public void main(String[] args)
e. none of the above
c
The Java compiler does the following:
a. checks a bytecode program in a ".class" file for run-time errors and if there are none, it generates source code for that program in a ".java" file
b. checks a source code program in a ".java" file for run-time errors and if there are none, it generates bytecode for that program in a ".class" file
c. checks a source code program in a ".java" file for compile-time errors and, if there are none, it generates bytecode for that program in a ".class" file
d. checks a bytecode program in a ".class" file for compile-time errors and if there are none, it generates source code for that program in a ".java" file
e. none of the above
c
Which statement correctly defines a java constant?
a. const SPECIAL = 1234;
b. int SPECIAL = 1234;
c. int final SPECIAL = 1234;
d. final int SPECIAL = 1234;
e. const int SPECIAL = 1234;
d
What is the value of s after the following statement:
String s = (!true) + " : " + (10 + 4) + " is 104";
a. "!true : 104 is 104"
b. "false : 104 is 104"
c. "!true : 14 is 104"
d. "false : 14 is 104"
e. This is a compile-time error
d
The Checkstyle plugin for Eclipse is useful because:
a. it warns you of potential compile-time errors
b. it helps you make your code understandable for yourself and other programmers
c. it prevents your code from making errors caught by assert statements
d. it tells you when code you have written does not obey its contract
e. none of the above
b
If x is an int variable, when does the boolean expression evaluate to true?
((x % 5 != 0) && (x % 2 != 0))
a. when x is divisible by 5 or by 2 but not by both
b. when x is divisible by 10
c. when x is not divisible by 10
d. when x is neither divisible by 5 nor by 2
e. when x is either divisible by 5 or by 2
d
The nextDouble( ) method of r, a variable of type Random, returns a double in a range of [0,1). Which of these expressions would you use to create a random number in the range of [-3,3)?
a. r.nextDouble( ) * 3.0 - 3.0
b. (r.nextDouble( ) - 0.5) * 6.0
c. r.nextDouble( ) * 6.0 + 3.0
d. r.nextDouble( ) * 6.0 + 0.5
e. (r.nextDouble( ) - 3.0) * 6.0
b
Consider the following code fragment:
int x = 8;
while ((x / 3) != 2) { x = x - 1; }
How many times will the body of the loop execute?
a. 0
b. 1
c. 2
d. 3
e. the loop will never terminate
a
Consider the following method signature:
private static int examScore(int studentNum) {...}
Here, studentNum is called:
a. distinguished variable
b. an argument
c. a formal parameter
d. an index
e. none of the above
c
What is the value of x after this statement?
double x = 1 / 2;
a. 0.0
b. 0.5
c. 1.0
d. 2.0
a
Consider the following method and the client code. What is true after the client code executes?
private static int m(int x, int y) {
y = x;
x = 0;
return y;
}
int num1 = 4, num 2 = 9;
num2 = m (num1, num2);
a. num1 = 0, num2 = 4
b. num1 = 0, num2 = 9
c. num1 = 4, num2 = 4
d. num1 = 4, num2 = 9
c
Consider the following array declaration and initialization. What is the value of the expression (a[1] + a[3])?
String [ ] a = {"A", "B", "C", "D" };
a. "AC"
b. "BD"
c. "ABC"
d. "CD"
b
Suppose you are trying to get a good estimate of √x using Newton Iteration, as described in project 2. The instructions are to continue iterating until "estimate of square root of x is within relative error 0.01%". Which while loop condition would be appropriate?
a. while(Math.abs(r - x) >= 0.001) { ... }
b. while(Math.abs(r - x) / x >= 0.001) { ... }
c. while(Math.abs(r * r - x) / x != 0.001) { ... }
d. while(Math.abs(r * r - x) / x > 0.001) { ... }
d
In design-by-contract, when the precondition (requires clause) of a method is not satisfied the implementer of a method is obligated to:
a. stop the program and report an error
b. generate a default result that will let the client know of their error
c. make sure the postcondition (ensures clause) is satisfied
d. none of the above
d
What is the value of k after this code completes?
int i = 0, j = 0, k = 0;
while (i < 3) {
i++;
j = 0;
while (j < 3) {
j++;
k = k + i + j;
} }
a. 36
b. 54
c. 9
d. 6
a
For this line of XML, what is the attribute name?
a. parts
b. dist
c. even
d. 5
b
Which is true of an XML tree?
a. only tag nodes have a label property
b. every node has an attribute property
c. only tag nodes may have children
d. only non-tag nodes can be leaf nodes
e. none of the above
c
Which is NOT a property of an RSS 2.0 feed?
a. the root is an rss node with a version attribute whose value is "2.0"
b. there are one or more channel nodes as a child of the root
c. the channel node must have one of each of these nodes as children: title, link, and description
d. the channel node can also have zero or more item child nodes plus other optional children
e. all the above are true for RSS 2.0
b
What can you say about these two methods m1 & m2?
private static boolean m1(int x, int y) {
boolean result;
if (x>0 && y > 0) { result = false; }
else { result = true; }
return result;
}
private static boolean m2(int x, int y)
{ return !(x > 0 && y > 0); }
a. both return the same result for all values of x and y
b. they return different values of x and y
c. m1 contains syntax errors
d. m2 contains syntax errors
e. both have syntax errors
a
Which is an appropriate method signature for a method p that will print a square of dollar signs ($) with a given output stream, and a given size of the square?
a. private static SimpleWriter p(int size, "$") { ... }
b. private static void p(out, size) { ... }
c. private static int p(SimpleWriter out, int size) { ... }
d. private static void p(SimpleWriter out, int size) { ... }
e. none of the above
d
An XMLTree created from an RSS 2.0 feed will have which of these properties?
a. the root is a node with the
b. child 0 of the
c. no particular order is required among the children of an <item> tag node
d. at least one child of the <item> tag node must be a <title> tag node
e. none of the above
c
Which of the following statements about this diagram is true?
(interface I1)
^ extends
(interface I2)
^ implements
[class C]
a. C is a description of what I2 does, not of how it does it
b. C implements the behavior/functionality provided in I1
c. I1 inherits all the methods declared in I2
d. I2 is the implementer view and I1 is the client view
e. none of the above
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? (hint: don't forget negative numbers!)
a. n % 2 == 1
b. n % 2 != 1
c. n % 2 == 0
d. n % 2 != 0
e. none of the above
d
Given the following code, which statement is true?
SimpleWriter out = new SimpleWriter1L( );
NaturalNumber n1 = new NaturalNumber1L(5);
NaturalNumber n2 = n1;
n2.decrement( );
out.println("n1 = " + n1 + ", n2 = " + n2);
a. will output "n1 = 4, n2 = 4"
b. will output "n1 = 5, n2 = 4"
c. will not compile
d. will result in a run-time error
e. none of the above
a
What is value of num after the following loop?
NaturalNumber n = new NaturalNumber2(25);
NaturalNumber hund = new NaturalNumber2(100);
NaturalNumber num = n;
while (n.compareTo(hund) < 0) {
n.multiply(new NaturalNumber2(2));
if (n.compareTo(num) > 0) {
num = n;
}
}
a. 25
b. 50
c. 100
d. 200
e. none of the above
c
Consider the following method contract and client code:
/**
* Adds n to this.
* @updates this
* @restores n
* @ensures this = #this + n
*/
public void add(NaturalNumber n) { ... }
NaturalNumber num = new NaturalNumber2(2);
num.add(num);
What is the value of num after the method call?
a. num = 0
b. num = 2 (not this)
c. num = 4
d. cannot tell from the information provided
d
What are the values of array and index after the call to bar?
private static void bar(int[ ] a, int i) {
a[i]++;
i++;
}
int[ ] array = { 1, 2, 3 };
int index = 1;
bar(array, index);
a. array = { 1, 2, 3 }; index = 1;
b. array = { 1, 2, 3 }; index = 2;
c. array = { 1, 3, 3 }; index = 1;
d. array = { 1, 3, 3 }; index = 2;
c
What will be the value of the array after this code executes?
NaturalNumber[ ] array = new NaturalNumber2[4];
NaturalNumber count = new NaturalNumber2(1);
for (int i = 0; i < array.length; i++) {
array[i].copyFrom(count);
count.increment( );
}
a. array = { 0, 0, 0, 0 }
b. array = { 1, 2, 3, 4 }
c. array = { 4, 4, 4, 4 }
d. there is an error in the code that will cause a runtime error
d
What line of code is missing from this method?
private static int size(XMLTree t) {
int totalNodes = 1;
[------------------------] // missing line
for (int i = 0; i < t.numberOfChildren( ); i++) {
totalNodes += size(t.child(i));
}
}
return totalNodes;
}
a. if (t.numberOfChildren( ) > 0) {
b. if (!t.label( ).equals("")) {
c. if (!t.isTag( )) {
d. if (t.isTag( )) {
d
After the two variables are declared and initialized, which java instruction will set the value of b to true?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber k = new NaturalNumber2(1);
a. boolean b = k.compareTo(n) == 1;
b. boolean b = n.compareTo(k) < 0;
c. boolean b = n <= k;
d. boolean b = n.!equals(k);
b
After execution of the following code, what are the declared type (static type) and the object type (dynamic type) of nCopy?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber nCopy = new NaturalNumber1L(n);
a. declared type is NaturalNumber, object type is NaturalNumber1L
b. declared type is NaturalNumber, object type is NaturalNumber2
c. declared type is NaturalNumber2, object type is NaturalNumber1L
d. declared type is NaturalNumber1L, object type is NaturalNumber2
a
The interval-halving technique can be used to efficiently compute results for problems like guessing numbers and finding roots because:
a. in Java, division by two throws away the remainder
b. all numbers involved in the computation are non-negative
c. 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
d. the function you are evaluating over the interval has no more than two maximum or minimum values in that interval
e. none of the above
c
The crucial theorem for recursion
a. to curse is human, to recurse is divine
b. if your code is correct when it calls a hypothetical version of the method on a smaller version of the problem, it will still me correct with a recursive call to your own version
c. all recursive solutions can also be done iteratively, but as a performance cost
d. recursive solutions always require more lines of code than iterative solutions for the same problem
b
The recursion "confidence building" argument
a. starts by proving that the method words for the largest value
b. starts by proving that the method does not work for the largest value
c. is most like mathematical induction
d. is most like proof by contradiction
c
Which parameter mode is the default? That is, which parameter mode should be assumed if no other parameter mode is explicitly indicated in the contract?
a. clears
b. restores
c. replaces
d. updates
e. removes
b
Indicating that a parameter is 'Replaces' mode...
a. means that the parameter's value might be changed from its incoming value in a way that depends on its incoming value
b. means that the outgoing value, in fact the entire behavior of the method, is independent of the incoming value of that parameter
c. is equivalent to adding "and x = #x" to the ensures clause
d. is equivalent to adding "and x = #x" to the requires clause
b
Which interface or class implementation of power will java
use for this call to power?
NaturalNumber k = new NaturalNumber2( );
NaturalNumber n = new NaturalNumber2Override( );
NaturalNumber j = n;
j.power(2);
a. NaturalNumber
b. NaturalNumber2
c. NaturalNumber2Override
d. NaturalNumberKernel
c
Which of the following is NOT true of Instance Methods?
a. may be public or private
b. may be called without a receiver
c. may return any type, or nothing (void)
d. may be declared in an interface
e. all the above are true
b
Which would NOT be a good input value for a test case of this method?
/**
* Decrements the given NaturalNumber.
* @updates n
* @requires
* n > 0
* @ensures
* n = #n - 1
* /
private static void decrement(NaturalNumber n) { ... }
a. #n = 1
b. #n = 10
c. #n = 42
d. #n = 0
e. they are all good test cases
d
When testing a method's functional correctness, what does it mean for a method to be correct?
a. it compiles and runs without errors
b. it does what it is supposed to do, and it doesn't do what it is not supposed to do
c. it passes all the test cases
d. it does not have any performance issues
e. none of the above
b
Which is true of JUnit testing when the unit under test is a single method?
a. JUnit testing can prove the correctness of the method body
b. JUnit testing is generally considered an expensive waste of time in industry
c. a single JUnit test case can show the presence of a defect in the method body
d. a single JUnit test case can show the absence of defects in the method body
e. none of the above are true
c
Consider the following code:
private static int examScore(int studentNumber) { ... }
int k = examScore(42);
This code would certainly...
a. be illegal in Java (it's a compile-time error)
b. cause the program to crash when it is executed (it is a run-time error)
c. print out the exam score of student #42
d. assign an exam score of 42 to student k
e. be legal in Java (though flagged by Checkstyle)
e
You may reason about the behavior of Java code involving immutable types exactly as if they were primitive types because:
a. "Immutable" and "primitive" are synonyms; there is no difference between them
b. computations involving immutable types are just as efficient as those involving primitive types
c. aliasing, which can happen with immutable types but not primitive types, cannot cause trouble because object values for immutable types cannot be changed
d. in any code where an immutable type is used in a way where it would not behave like a primitive type, it causes a Java compile-time error
c
What are the values of str and num after the call to foo?
private static void foo(String s, NaturalNumber n) {
s = "Columbus, " +s;
n = new NaturalNumber2(43210);
}
String str = "Ohio";
NaturalNumber num = new NaturalNumber2(314);
foo(str, num);
a. str="Ohio", num=314
b. str="Columbus, Ohio", num=314
c. str="Ohio", num=43210
d. str="Columbus, Ohio", num=43210
c
A type is an immutable type if:
a. it is illegal to copy a reference of that type, so there can be no aliasing
b. for every instance method of that type, this and every other parameter of that type is a restores-mode parameter
c. that type has a no-argument constructor
d. a function method may not return a result of that type
b
JVM stands for:
a. Java Virtual Manager
b. Java Virtual Memory
c. Java Virtual Machine
d. Java Variable Mathematics
e. none of the above
c
API stands for:
a. Advanced Programming Index
b. Advanced Power Interface
c. Access Port Input
d. Application Personal Interface
e. Application Programming Interface
e
Which four Javadoc tags are required for this method?
private static double sqrt(double x) { ... }
a. @param, @return, @updates
b. @param, @return, @replaces
c. @author, @version, @return
d. @param, @return, @ensures
d
Which of the Stack methods will add an int to the top of x?
a. x.pop(int 42);
b. x.append(int 42);
c. x.enqueue(int 42);
d. x.top(int 42);
e. x.push(int 42);
e
Which of the following are true of Sets?
1. There is no empty set
2. There are no duplicate elements
3. There is no order among the elements
a. only 3 is true
b. 1 and 3 are true
c. 2 and 3 are true
d. they are all true
e. none are true
c
What represents an ordered Java component?
a. { }
b. < >
c. [ ]
d. ( )
e. " "
b
What represents an unordered Java component?
a. < >
b. [ ]
c. " "
d. { }
e. ( )
d
What is the size and height of this XMLTree?
a. size = 5 height = 3
b. size = 6 height = 4
c. size = 7 height = 5
d. size = 8 height = 4
e. size = 6 height = 5
c
Provided by the code calling the method:
a. argument
b. variable
c. formal parameter
d. constant
e. expression
a
Method's post condition is documented in this clause:
a. formal parameter
b. requires
c. method signature
d. ensures
e. returns
d
Smallest complete unit of execution in Java:
a. variable
b. statement
c. type
d. expression
e. constant
b
Variable that is declared and initialized, but never changed:
a. final
b. static variable
c. literal
d. formal parameter
e. constant
e
Views the system from the inside:
a. JVM
b. implementer
c. client
d. user
e. eclipse
b
Includes return type, name, and parameter list:
a. formal parameter
b. requires clause
c. ensures clause
d. statement
e. method signature
e
How would you get n to be the last digit (n % 10) of NaturalNumber n (assume nCopy is not aliased with n and n is a NaturalNumber)?
a. n.divide(10)
b. n = nCopy.divide(10)
c. n.divideBy10( )
d. n = nCopy.divideBy10( );
e. none of the above will give (n % 10)/last digit of n
b
Refer to the code below. When the program ends, what will be the value of the variable b?
NaturalNumber b = new NaturalNumber2(4);
b.add(b.divide(2));
a. b = 0
b. b = 2
c. b = 4
d. b = 6
e. b = 8
b
Refer to the code below. When the program ends, what will be the value of the elements in the nums array?
private static void foo(NaturalNumber[ ] arr) {
arr[0] = new NaturalNumber2(2);
arr[1].multiply(arr[0]);
}
NaturalNumber[ ] nums = new NaturalNumber2[2];
nums[0] = new NaturalNumber2(1);
nums[1] = new NaturalNumber2(2);
foo(nums);
a. nums[0] = 1; nums [1] = 2
b. nums[0] = 1; nums [1] = 4
c. nums[0] = 2; nums [1] = 2
d. nums[0] = 2; nums [1] = 4
e. Error: null pointer exception
d
Refer to the code below. When the program ends what is the value of a?
private static void foo(NaturalNumber n) {
n.increment( );
n = new NaturalNumber2(5);
}
NaturalNumber a = new NaturalNumber2(3);
foo(a);
a. 3
b. 4
c. 5
d. impossible to tell
e. compile-time error
b
GUI in Java typically stands for
a. Graphical Unit Interface
b. General User Interface
c. Graphical User Interface
d. Generic Unix Installer
e. Geese Under Igloos
c
MVC in Java typically stands for
a. Model Virtual Controller
b. Motor Vehicle Collision
c. Mainframe View Controller
d. Model Virtual Computer
e. Model View Controller
e
industry-standard library for unit-testing software components
JUnit
industry-standard documentation utility for Java programs
Javadoc
information interpreted by the Java Virtual Machine upon execution of a Java program
bytecode
keyword written before a package name to include external components in a Java program
import
keyword indicating that a class cannot be changed by inheritance or that a variable is a constant
final
providing a name and a location for a variable to store its value
variable declaration
assigning a value to a variable for the first time
variable initialization
character literal have single or double quotes?
single
string literal have single or double quotes?
double
a syntactically well-formed and meaningful fragment (has a value)
expression
a smalles complete unit of execution (usually terminates with a ;)
statement
method name and parameter types
method signature
method return type, method name, and method parameter list
method header
the individual viewing a system from the outside (as a single indivisible unit)
client
the individual viewing a system from the inside (as an assembly of components)
implementer
meeting this characterizes the responsibility of the client code
precondition
meeting this characterizes the responsibility of the implementation code in the method body
postcondition
parameters in the method header, is in paratheneses in the method header
formal parameter
the call for the method in the main method
argument
when writing methods, should you check the preconditions with if statements
no
aliasing refers to:
two reference values referring to the same object value
testing the behavior of a single method or component is better known as:
unit testing
instance methods can only be private
false
instance methods may be static or non-static
false
instance methods may have any return type, including void
true
in the call n.foo(x), x is known as the receiver of the call
false
the reference value of a reference variable is related to the object's location in memory
true
the reference value of a reference variable is related to the object's mathematical value
false
if you have a thorough test plan and your method passes all of the tests in it, you have proven that your method is correct
false
testing and debugging are synonyms for the same process
false
best practice for using Unit is to write one method that contains logic for all your test cases for the unit under test
false