Skip to main content

Computer Science II Exam Materials - 2169 Verified Questions

Page 1


Computer Science II

Exam Materials

Course Introduction

Computer Science II is a continuation of foundational programming courses, focusing on advanced programming concepts, data structures, and algorithms. Students will develop proficiency in using structured and object-oriented programming techniques to solve complex computational problems. Topics covered often include arrays, linked lists, stacks, queues, recursion, searching and sorting algorithms, and basic software engineering principles. The course emphasizes analytical thinking, code efficiency, and collaborative software development projects, preparing students for upper-level courses and practical applications in computer science.

Recommended Textbook

Big Java Late Objects 1st Edition by Cay S. Horstmann

Available Study Resources on Quizplus

24 Chapters

2169 Verified Questions

2169 Flashcards

Source URL: https://quizplus.com/study-set/3769

Page 2

Chapter 1: Introduction

Available Study Resources on Quizplus for this Chatper

96 Verified Questions

96 Flashcards

Source URL: https://quizplus.com/quiz/75165

Sample Questions

Q1) Which one of the following translates high-level descriptions into machine code?

A) Assembler

B) Linker

C) Compiler

D) Editor

Answer: C

Q2) Every statement in Java must be terminated with )

A) the semi-colon character ;.

B) a carriage return.

C) System.out.println().

D) an escape sequence.

Answer: A

Q3) The Central Processing Unit is primarily responsible for A) performing program control and data processing.

B) ensuring data persists when electrical power is turned off.

C) enabling a human user to interact with the computer.

D) interconnecting computers that are separated by distance.

Answer: A

To view all questions and flashcards with answers, click on the resource link above.

Page 3

Chapter 2: Fundamental Data Types

Available Study Resources on Quizplus for this Chatper

103 Verified Questions

103 Flashcards

Source URL: https://quizplus.com/quiz/75166

Sample Questions

Q1) What output is produced by these statements?

String name = "Joanne Hunt"; System.out.println(name.length());

A) 8

B) 10

C) 9

D) 11

Answer: D

Q2) What are the values of num1 and num2 after this snippet executes?

Double num1 = 4.20; Double num2 = num1 * 10 + 5.0;

A) num1 = 4.20 and num2 = 63.0

B) num1 = 4.20 and num2 = 47.0

C) num1 = 42.0 and num2 = 42.0

D) num1 = 42.0 and num2 = 47.0

Answer: B

To view all questions and flashcards with answers, click on the resource link above. Page 4

Chapter 3: Decisionseasy

Available Study Resources on Quizplus for this Chatper

99 Verified Questions

99 Flashcards

Source URL: https://quizplus.com/quiz/75167

Sample Questions

Q1) Which statement about an if statement is true?

A) The condition in an if statement using relational operators will evaluate to a Boolean result

B) The condition in an if statement should make exact comparisons to floating-point numbers

C) The condition in an if statement should always evaluate to true

D) The condition in an if statement should never include integer variables

Answer: A

Q2) The following code snippet contains an error. What is the error?

If (cost > 100);

{ Cost = cost - 10;

}

System.out.println("Discount cost: " + cost);

A) Syntax error (won't compile)

B) Logical error: use of an uninitialized variable

C) Logical error: if statement has do-nothing statement after if condition

D) Logical error: assignment statement does not show equality

Answer: C

To view all questions and flashcards with answers, click on the resource link above. Page 5

Chapter 4: Loops

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75168

Sample Questions

Q1) What is the last output line of the code snippet given below?

Int i = 5; While (i >= 1)

{

Int num = 1; For (int j = 1; j <= i; j++)

{

System.out.print(num + "**");

Num = num * 2;

}

System.out.println();

I = i - 1; }

A) No output

B) 1**2

C) 1**2**3

D) 1**

To view all questions and flashcards with answers, click on the resource link above.

Page 6

Chapter 5: Methods

Available Study Resources on Quizplus for this Chatper

94 Verified Questions

94 Flashcards

Source URL: https://quizplus.com/quiz/75169

Sample Questions

Q1) Which statement about the steps for implementing a method is true?

A) Pseudocode is the first step in the process for implementing a method

B) Pseudocode is the last step in the process for implementing a method

C) Unit testing (testing in isolation) of the implemented method is an important first step

D) Unit testing (testing in isolation) of the implemented method is an important final step

Q2) Given the following method, what is the result of getNumber(n)?

Public static double getNumber(double n)

{ Return Math.pow(Math.sqrt(n), 2) - n;

}

A) Always 0 for every argument n

B) Always 2 for every argument n

C) Close to 0, but not always 0

D) Compilation error

To view all questions and flashcards with answers, click on the resource link above. Page 7

Chapter 6: Arrays and Arraylists

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75170

Sample Questions

Q1) In a partially filled array, the number of slots in the array that are not currently used is

A) the length of the array minus the number of elements currently in the array

B) the number of elements currently in the array minus the length of the array

C) the length of the array plus the number of elements currently in the array

D) the number of elements currently in the array

Q2) Which one of the following statements is the correct definition for a two-dimensional array of 20 rows and 2 columns of the type integer?

A) int[][] num = new int[20][2];

B) int[][] num = new int[2][20];

C) int[][] num = new int[20,2];

D) int[][] num = new int[2,20];

Q3) Why is the use of physical objects helpful in algorithm design?

A) It simulates the way the computer actually implements the algorithm

B) It is more abstract than using a pencil and paper

C) Because the constraints on physical things are the same as the constraints on bits and bytes

D) Many people feel it is less intimidating than drawing diagrams

To view all questions and flashcards with answers, click on the resource link above. Page 8

Chapter 7: Inputoutput and Exception Handling

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75171

Sample

Questions

Q1) Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt that resides in a folder named payroll on the C: drive of a Windows system.

Public static void main(String[] args) throws FileNotFoundException

{

File inputFile = ________; Scanner in = new Scanner(inputFile); ) . .

}

A) new File(c:/payroll/"dataIn.txt")

B) new File(c://payroll//"dataIn.txt")

C) new File("c:\payroll\dataIn.txt")

D) new File("c:\\payroll\\dataIn.txt")

Q2) In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

A) ArithmeticException.

B) ClassCastException.

C) IllegalArgumentException.

D) IllegalStateException.

To view all questions and flashcards with answers, click on the resource link above. Page 9

Chapter 8: Objects and Classes

Available Study Resources on Quizplus for this Chatper

101 Verified Questions

101 Flashcards

Source URL: https://quizplus.com/quiz/75172

Sample Questions

Q1) Which of the following statements is true regarding classes?

A) Each object of a class has a separate copy of each instance variable.

B) All objects created from a class share a single set of instance variables.

C) Private instance variables can be accessed by any user of the object.

D) Public instance variables can be accessed only by the object itself.

Q2) Consider the following code snippet:

Public class Vessel

{ Private String type; Public String Vessel(String type)

{

What is wrong with this code?

A) The class instance variable type must be initialized when it is declared.

B) The constructor must not have any arguments.

C) The constructor must not have a return type declared.

D) The constructor's return type must be void.

To view all questions and flashcards with answers, click on the resource link above.

Page 10

Chapter 9: Inheritance and Interfaces

Available Study Resources on Quizplus for this Chatper

99 Verified Questions

99 Flashcards

Source URL: https://quizplus.com/quiz/75173

Sample Questions

Q1) Which of the following indicates that the Motorcycle class is a subclass of the Vehicle class?

A) public class Motorcycle extends Vehicle

B) public class Motorcycle implements Vehicle

C) public class Vehicle extends Motorcycle

D) public class Vehicle implements Motorcycle

Q2) Consider the following code snippet: Int vacationDays = 10; String output = "Number of earned vacation days is " + vacationDays; Which of the following statements is correct?

A) The toString method of the Object class is being used to set the value of output.

B) The toString method of the Integer class is being used to set the value of output.

C) No toString method is being used to set the value of output.

D) This code will not compile.

To view all questions and flashcards with answers, click on the resource link above.

11

Chapter 10: Graphical User Interfaces

Available Study Resources on Quizplus for this Chatper

54 Verified Questions

54 Flashcards

Source URL: https://quizplus.com/quiz/75174

Sample Questions

Q1) Insert the missing statement(s) in the following code fragment. The code is intended to display a message "Your cost is: " in a text area and display the cost on the next line. Double cost = 500.99; String message = "Your cost is:"; JTextArea result = new JTextArea(10, 30);

Result.setEditable(false);

A) result.setText(message);

Result.append(cost);

B) result.addText(message + "\n" + cost);

C) result.append(message + cost);

D) result.setText(message + "\n");

Result.append(cost);

Q2) An event listener for a button must implement the ____ interface.

A) EventListener

B) ActionListener

C) ActionEvent

D) ActionPerformed

To view all questions and flashcards with answers, click on the resource link above.

12

Chapter 11: Advanced User Interfaces

Available Study Resources on Quizplus for this Chatper

91 Verified Questions

91 Flashcards

Source URL: https://quizplus.com/quiz/75175

Sample Questions

Q1) Which of the following statements is correct?

A) new JSlider() creates a horizontal slider with the range 0 to 200 and an initial value of 100.

B) new JSlider() creates a horizontal slider with the range 0 to 10 and an initial value of 5.

C) new JSlider() creates a horizontal slider with the range 0 to 100 and an initial value of 50.

D) new JSlider() creates a horizontal slider with the range 0 to 150 and an initial value of 100.

Q2) When the user selects a menu item, the menu item sends a(n)

A) ActionEvent

B) ChangeEvent

C) ItemEvent

D) MouseEvent

Q3) A(n) ____ is used to capture mouse events.

A) action listener

B) event listener

C) mouse listener

D) component listener

To view all questions and flashcards with answers, click on the resource link above.

Page 13

Chapter 12: Object-Oriented Design

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75176

Sample Questions

Q1) Which of the following code snippets denotes that the Kitchen class depends on the Stove class?

A) public class Kitchen extends Stove

B) public class Stove

{ Private Kitchen[] kitchens; }

C) public class Kitchen { Private Stove aStove; }

D) public class Kitchen implements Stove

Q2) Why is it generally considered good practice to minimize coupling between classes?

A) Low coupling increases the operational efficiency of a program.

B) High coupling implies less interface cohesion.

C) High coupling increases program maintenance and hinders code reuse.

D) Low coupling decreases the probability of code redundancy.

To view all questions and flashcards with answers, click on the resource link above. Page 14

Chapter 13: Recursion

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75177

Sample Questions

Q1) Consider the getArea method from the textbook shown below. Public int getArea()

{ If (width <= 0) { return 0; } // line #1

If (width == 1) { return 1; } // line #2

Triangle smallerTriangle = new Triangle(width - 1); // line #3

Int smallerArea = smallerTriangle.getArea(); // line #4

Return smallerArea + width; // line #5

}

Assume that line #2 is changed to this:

If (width == 1) { return 2; }

How would this affect calls to getArea?

A) It would add 1 to all calls except those where width <= 0.

B) It would make no difference to any call.

C) It would double every triangle area.

D) It would subtract 1 from all calls.

To view all questions and flashcards with answers, click on the resource link above.

15

Chapter 14: Sorting and Searching

Available Study Resources on Quizplus for this Chatper

99 Verified Questions

99 Flashcards

Source URL: https://quizplus.com/quiz/75178

Sample Questions

Q1) Which of the sorts in the textbook can be characterized by the fact that even in the worst case the running time will be O(n log(n)))?

I quicksort

II selection sort

III merge sort

A) I

B) II

C) III

D) I and III

Q2) Which sort algorithm is used in the sort method in the Java Arrays class when the array length is less than 7?

A) merge sort

B) quicksort

C) selection sort

D) insertion sort

To view all questions and flashcards with answers, click on the resource link above. Page 16

Chapter 15: The Java Collections Framework

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75179

Sample Questions

Q1) Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly add an element to myStack?

A) myStack.put("apple");

B) myStack.addItem("apple");

C) myStack.push("apple");

D) myStack.insert("apple");

Q2) Consider the following code snippet: Map&lt;String, Integer&gt; scores;

If you need to visit the keys in sorted order, which of the following statements will create a structure to support this?

A) scores = new HashMap&lt;String, Integer&gt;;

B) scores = new TreeMap&lt;String, Integer&gt;;

C) scores = new Map&lt;String, Integer&gt;;

D) scores = new HashTable&lt;String, Integer&gt;;

Q3) Which method is NOT part of the ListIterator generic class?

A) hasNext

B) hasMore

C) hasPrevious

D) add

To view all questions and flashcards with answers, click on the resource link above.

Page 17

Chapter 16: Basic Data Structures

Available Study Resources on Quizplus for this Chatper

94 Verified Questions

94 Flashcards

Source URL: https://quizplus.com/quiz/75180

Sample Questions

Q1) Which of the following statements about handling collisions in a hash table using the sequential chaining and open addressing techniques is NOT correct?

A) The implementation of sequential chaining technique is simpler than the implementation of the open addressing technique.

B) The sequential chaining technique is simpler to understand than the open addressing technique.

C) The sequential chaining technique requires the storage of links while open addressing does not.

D) The sequential chaining technique requires less memory use than open addressing.

Q2) What feature of the ArrayList class makes it much better for a binary search than the LinkedList class?

A) indexing

B) has no link references

C) it is a generic class

D) it is an abstract class

To view all questions and flashcards with answers, click on the resource link above.

18

Chapter 17: Tree Structures

Available Study Resources on Quizplus for this Chatper

100 Verified Questions

100 Flashcards

Source URL: https://quizplus.com/quiz/75181

Sample Questions

Q1) Adding an element to a balanced binary search tree takes ____ time.

A) O(n)

B) O(log (n))

C) O(1)

D) O(n<sup>2</sup>)

Q2) What is the efficiency of the heapsort algorithm?

A) O(1)

B) O(log (n))

C) O(n log (n))

D) O(n<sup>2</sup>)

Q3) You are using a tree to show the evaluation order of arithmetic expressions. Which of the following statements is NOT correct?

A) Leaves contain numbers.

B) Interior nodes contain numbers.

C) The root contains an operator.

D) Every level of the tree must contain an operator.

To view all questions and flashcards with answers, click on the resource link above. Page 19

Chapter 18: Generic Classes

Available Study Resources on Quizplus for this Chatper

78 Verified Questions

78 Flashcards

Source URL: https://quizplus.com/quiz/75182

Sample Questions

Q1) Consider the following code snippet: Public class Box&lt;E&gt; { Private E data; Public Box(){ . . . } Public void insert(E value) { . . . }

Public E getData(){ . . . } }

What specific exception will be thrown when the following code executes? Box&lt;String&gt; box = new Box&lt;String&gt;(); ) . .

Box)insert("blue Box"); Double myDouble = (Double) box.getData();

A) Exception

B) NoSuchElementException

C) IndexOutOfBoundsException

D) ClassCastException

To view all questions and flashcards with answers, click on the resource link above. Page 20

Chapter 19: Streams and Binary Inputoutput

Available Study Resources on Quizplus for this Chatper

82 Verified Questions

82 Flashcards

Source URL: https://quizplus.com/quiz/75183

Sample Questions

Q1) Assume we have a RandomAccessFile object, file, which stores a set of records of class MyData, each needing MyData.RECORD_SIZE bytes for storage. Which expression calculates the number of records in the file?

A) MyData.RECORD_SIZE * file.length()

B) MyData.RECORD_SIZE + file.getFilePointer()

C) file.seek(0L) / MyData.RECORD_SIZE

D) file.length() / MyData.RECORD_SIZE

Q2) Which interface allows classes to be written to an ObjectOutputStream?

A) Objective

B) Streaming

C) Serializable

D) Objectifiable

Q3) A file pointer is a position in a random access file. Because files can be very large, The file pointer is of type _______.

A) double

B) byte

C) int

D) long

To view all questions and flashcards with answers, click on the resource link above.

Chapter 20: Multithreading

Available Study Resources on Quizplus for this Chatper

82 Verified Questions

82 Flashcards

Source URL: https://quizplus.com/quiz/75184

Sample Questions

Q1) Suppose run1 and run2 are objects of the class MyRunnable, which implements the Runnable interface. What is the result of the following calls?

Run1.run();

Run2.run();

A) run1 and run2 execute as independent threads.

B) Syntax error

C) Only run1 executes as an independent thread.

D) run1 and run2 run sequentially, not as independent threads.

Q2) Which of the following does not create an object that can run in a thread, assuming the following MyRunnable class declaration?

Public class MyRunnable implements Runnable { . . . }

I Runnable runnable = new Runnable();

II Runnable runnable = new MyRunnable();

III MyRunnable runnable = new MyRunnable();

A) I

B) III

C) I and II

D) II and III

To view all questions and flashcards with answers, click on the resource link above. Page 22

Chapter 21: Internet Networking

Available Study Resources on Quizplus for this Chatper

74 Verified Questions

74 Flashcards

Source URL: https://quizplus.com/quiz/75185

Sample Questions

Q1) What are among the most important pieces of information that must be included in an IP packet?

I. The Internet address of the recipient

II. The URL of the recipient

III. The Internet address of the sender

IV. The port number of the sender

A) I, III, and IV

B) I, II, and III

C) II, III, and IV

D) I, II, III, and IV

Q2) Suppose you use the URLGet program in Section 21.5 to get a web page that does not exist on a server (which does exist). Assuming that the server is otherwise working properly, what will happen?

A) The call to openConnection will throw an exception.

B) The call to getResponseCode will return the error code 404.

C) The call to getResponseMessage will return null.

D) The call to getInputStream will throw an exception.

To view all questions and flashcards with answers, click on the resource link above. Page 23

Chapter 22: Relational Databases

Available Study Resources on Quizplus for this Chatper

75 Verified Questions

75 Flashcards

Source URL: https://quizplus.com/quiz/75186

Sample Questions

Q1) The ______ clause is used to select data that fulfill a condition

A) SELECT

B) FROM

C) WHEN

D) WHERE

Q2) An example of a desktop database is:

A) Oracle

B) MS Access

C) Apache Derby

D) MySQL

Q3) Which of the following would be a good primary key for a Course table designed to hold course information for a university?

A) CourseName

B) CourseID

C) CourseCredit

D) CoursePrerequisites

To view all questions and flashcards with answers, click on the resource link above.

Page 24

Chapter 23: XML

Available Study Resources on Quizplus for this Chatper

74 Verified Questions

74 Flashcards

Source URL: https://quizplus.com/quiz/75187

Sample Questions

Q1) A _____________ reads and reports on each element of an XML document as it reads it.

A) DOM parser

B) tree-based parser

C) block parser

D) streaming parser

Q2) Using the grammar notation in your textbook, which rule means that a verb can be either jumps over or eats?

A) &lt;verb&gt; ::= "jumps over" | "eats" | &lt;/verb&gt;

B) &lt;verb&gt; ::= jumps over | eats

C) &lt;verb&gt; ::= jumps | over | eats

D) &lt;verb&gt; ::= &lt;jumps over&gt; | &lt;eats&gt; | &lt;/verb&gt;

Q3) You set element attributes with the _________method.

A) setElementAttributes

B) setElement

C) setAttributes

D) setAttribute

To view all questions and flashcards with answers, click on the resource link above.

Chapter 24: Web Applications

Available Study Resources on Quizplus for this Chatper

74 Verified Questions

74 Flashcards

Source URL: https://quizplus.com/quiz/75188

Sample Questions

Q1) Which of the following represents part of the business logic of a three-tier application?

A) Web browser

B) The database

C) JSF container

D) The network

Q2) One of the steps in deploying a JSF application is to _______ of the web application:

A) Create a WEB-INF subdirectory in the root directory of the application directory

B) Create an INF-WEB subdirectory in the root directory of the application directory

C) Create a WEB-INF subdirectory in the application directory

D) Create a WEB-INF/classes subdirectory in the root directory of the application directory

Q3) JSF pages define the ___________ of a web application.

A) swings

B) presentation logic

C) business logic

D) value expressions

To view all questions and flashcards with answers, click on the resource link above.

26

Turn static files into dynamic content formats.

Create a flipbook
Computer Science II Exam Materials - 2169 Verified Questions by Quizplus - Issuu