


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive review for osu cse 2221 final exam, covering key concepts in java programming. It includes a series of multiple choice questions with detailed answers, focusing on topics such as method signatures, java compiler functionalities, constant definitions, string manipulation, and more. the questions test understanding of core java programming principles and problem-solving skills. This resource is valuable for students preparing for their final exam.
Typology: Exams
1 / 42
This page cannot be seen from the preview
Don't miss anything!
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
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. b. 0. c. 1. d. 2. 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 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. 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
Consider the following method contract and client code: /**
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?
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. NaturalNumber 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? /**
b. cause the program to crash when it is executed (it is a run-time error) c. print out the exam score of student # 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= b. str="Columbus, Ohio", num= c. str="Ohio", num= d. str="Columbus, Ohio", num= 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
d. { } e. ( ) d What is the size and height of this XMLTree?
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