Introduction to Computer Science Test Bank - 2169 Verified Questions

Page 1


Introduction to Computer Science Test

Bank

Course Introduction

Introduction to Computer Science provides students with a foundational understanding of the core concepts and principles underlying the field of computer science. The course covers topics such as algorithms, programming fundamentals, data structures, problem-solving techniques, software development practices, and the basics of computer hardware and software. Through hands-on projects and exercises, students learn to design, write, test, and debug programs using a high-level programming language. This course also explores the impact of computing on society, ethical considerations, and emerging trends in technology, preparing students for further study in computer science or related disciplines.

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) Consider the following statements about computer programs:

I. Computer programs can be written by someone who has a basic knowledge of operating a computer.

II. Computer programs can complete complex tasks quickly.

III. Large and complex computer programs are generally written by a group of programmers.

IV. Computer programs are composed of extremely primitive operations. Which one of the following options is correct?

A) II and III only are correct statements.

B) I, II, III and IV are correct statements.

C) II, III, and IV only are correct statements.

D) I and IV only are correct statements.

Answer: C

Q2) The source code for a Java program is stored in a file

A) that ends with a .class suffix

B) that can have any valid file name

C) that ends with a .java suffix

D) that has no suffix

Answer: C

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 is the output of the following code snippet?

Public static void main(String[] args)

{ Int s;

Double f = 365.25; S = f / 10; System.out.println(s);

A) 36

B) 36.525

C) 37

D) No output because the code snippet generates compilation errors

Answer: A

Q2) What is the value of Math.pow(2, 3)?

A) 5

B) 6

C) 8

D) 9

Answer: C

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) What is the output of the following code snippet?

String someString1 = "his";

String someString2 = "cycle"; If (someString1.compareTo(someString2) < 0)

{ System.out.println(someString2);

} Else

{ System.out.println(someString1);

}

A) his

B) hiscycle

C) cycle

D) There is no output due to compilation errors.

Answer: A

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) In the following code snippet, when does the execution of the program switch from the inner loop to the outer loop?

Int i;

Int j;

For (i = 0; i <= 9; i++)

{ For (j = 1; j < 5; j++)

{ System.out.println("Hello");

If (j == 2)

{ J = 6;

A) When the value of j becomes 6

B) When the program executes completely

C) When the condition for the outer loop is met

D) When the value of i is incremented

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

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) For the given code snippet, which of the following statements is true? Public static double raise(double rate)

{ Double newPayRate = rate * 1.1; Return newPayRate; }

Public static void main(String[] args)

{

Double rate = 40.0; Double newPayRate = 0.0; NewPayRate = raise(rate); System.out.println("Pay rate: " + newPayRate);

}

A) The code snippet executes and displays "Pay rate: 40.0"

B) The code snippet executes and displays "Pay rate: 44.0"

C) The code snippet executes and displays "Pay rate: 0.0"

D) There is no output because the program does not compile

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

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) Which one of the following is a correct declaration for a method named passAList that has as arguments an array list myList of size 10 and an integer array intArr of size 20, and that modifies the contents of myList and intArr?

A) public static void passAList(ArrayList&lt;Integer&gt; myList(10), int[] intArr)

B) public static void passAList(ArrayList&lt;Integer&gt; myList, int[20] intArr)

C) public static void passAList(ArrayList&lt;Integer&gt; myList, int[] intArr)

D) public static void passAList(ArryaList&lt;Integer&gt; myList, int intArr)

Q2) Which one of the following statements is correct for displaying the value in the second row and the third column of a two-dimensional, size 3 by 4 array?

A) System.out.println(arr[1][2]);

B) System.out.println(arr[2][3]);

C) System.out.println(arr[2][1]);

D) System.out.println(arr[3][2]);

Q3) The binary search is faster than the linear search, providing

A) the size of the array is a power of two.

B) the elements of the array are ordered.

C) the elements of the array are unordered.

D) the element being searched for is actually in the array.

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

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) Consider the following code snippet: PrintWriter outputFile = new PrintWriter(filename); WriteData(outputFile); OutputFile.close();

How can the program ensure that the file will be closed if an exception occurs on the writeData call?

A) The program does not need to take any action, because the output file will be automatically closed when the exception occurs.

B) The program should place the outputFile.close() statement within a try block to ensure that the file will be closed.

C) It is not possible to ensure that the file will be closed when the exception occurs.

D) The program should place the outputFile.close() statement within a finally clause of a try block to ensure that the file is closed.

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

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) You have created a Coin class and a Purse class. Which of the following methods will correctly add a Coin object to an array list named coins in the Purse class?

A) public void add(Coin aCoin)

{ Coins.add(new Coin(aCoin));

B) public void add(Coin aCoin)

{ Coins.add(aCoin);

C) public void add(Coin aCoin)

{ Coins.addItem(new Coin(aCoin));

D) public void add(Coin aCoin)

{ Coins.addItem(aCoin);

}

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) Consider the following code snippet: Public void deposit(double amount)

{ TransactionCount ++; Super.deposit(amount); }

Which of the following statements is true?

A) This method will call itself.

B) This method calls a public method in its subclass.

C) This method calls a private method in its superclass

D) This method calls a public method in its superclass.

Q2) Which statement about methods in an interface is true?

A) All methods in an interface are automatically private.

B) All methods in an interface are automatically public.

C) All methods in an interface are automatically static.

D) All methods in an interface must be explicitly declared as private or public.

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) Which of the following is an event source?

A) A JButton object.

B) An event listener.

C) An inner class.

D) An event adapter.

Q2) Which of the following statements about listener classes is true?

A) A listener class can be declared as an anonymous inner class.

B) A listener class cannot be declared as an inner class.

C) A listener class must be declared as an inner class.

D) A listener class must be declared as an anonymous inner class.

Q3) Which of the following statements is correct?

A) Methods of an inner class can access instance variables from the surrounding scope.

B) If an interface variable refers to an object, then the object need not belong to a class.

C) It is illegal to have variables whose type is an interface.

D) Methods of an inner class cannot access final variables from the surrounding scope.

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

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) A ____ is a combination of a list and a text field.

A) radio button

B) combo box

C) check box

D) scroll bar

Q2) When using a combo box, the _______ displays the name of the current selection.

A) text field

B) text area

C) menu item

D) submenu item

Q3) The _______ interface toolkit has a large set of user-interface components.

A) GUI Builder

B) graphical user

C) Swing

D) JMenu

Q4) What type does the method getSelectedItem in the JComboBox class return?

A) Object

B) String

C) JRadioButton

D) JLabel

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) How does a UML diagram denote classes and their attributes and methods?

A) A class rectangle contains the class name in the top, methods in the middle, and attributes in the bottom.

B) A class rectangle contains the class name in the top, attributes in the middle, and methods in the bottom.

C) A class rectangle contains the methods in the top, class name in the middle, and attributes in the bottom.

D) A class rectangle contains the attributes in the top, methods in the middle, and class name in the bottom.

Q2) A class (ClassOne) is considered to have a dependency on another class (ClassTwo) under which of the following conditions?

A) Each class uses objects of the other.

B) The public interfaces of both classes are cohesive.

C) ClassTwo uses objects of ClassOne.

D) ClassOne uses objects of ClassTwo.

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

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

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

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

Return smallerArea + width; // line #4

}

If line#1 was removed, what would be the result?

A) The recursive method would cause an exception for values below 0.

B) The recursive method would construct triangles whose width was negative.

C) The recursive method would terminate when the width reached 0.

D) The recursive method would correctly calculate the area of the original triangle.

Q2) In recursion, the terminating condition is analogous to a loop _________.

A) call

B) iteration

C) termination condition

D) initialization condition

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) If an element is present in an array of length n, how many element visits, in the worst case, are necessary to find it using a linear search?

A) n / 2

B) n

C) 2n

D) n<sup>2</sup>

Q2) In the textbook, we determined that the merge method requires a total of 5n visits. We found that the number of visits required to sort an array of n elements is T(n) = T(n / 2) + T(n / 2) + 5n. What does T(n / 2) describe?

A) the total number of visits to merge sort an array of n elements

B) half the number of visits to merge sort an array of n elements

C) the total number of visits to merge sort an array of n / 2 elements

D) half the number of visits to merge sort an array of n / 2 elements

Q3) What is the worst-case performance of insertion sort?

A) O(n)

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

C) O(log (n))

D) O(n log (n))

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) 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;;

Q2) What is included in a linked list node?

I a reference to its neighboring nodes

II an array reference

III a data element

A) I

B) II

C) II and III

D) I and III

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

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) 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

Q2) In the textbook implementation, the Node class is a private inner class of the LinkedList class. Which of the following statements regarding this implementation is NOT correct?

A) The methods of the LinkedList class can access the public features of the Node class.

B) The methods of the Node class can access the public features of the LinkedList class.

C) The methods of the Node class can be directly accessed by other classes.

D) The Node class's instance variables that represent the node element and its next node reference are declared as public.

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

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) A completely filled binary tree with a height of 4 has ____ nodes.

A) 8

B) 12

C) 15

D) 16

Q2) A completely filled binary tree with a height of 3 has ____ nodes.

A) 6

B) 7

C) 8

D) 12

Q3) What is the complexity of removing an element from a heap?

A) O(1)

B) O(log (n))

C) O(n log (n))

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

Q4) What is the efficiency of locating an element in a red-black tree?

A) O(n)

B) O(log (n))

C) O(1)

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

Page 19

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

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:

ArrayList&lt;Coin&gt; coins1 = new ArrayList&lt;Coin&gt;(); //Line 1

LinkedList coins2 = new LinkedList(); //Line 2

Coins1.add("my penny"); //Line 3

Coins2.addFirst("my penny"); //Line 4

Which of the above lines will cause a run-time error when the object is retrieved elsewhere in the program?

A) Line 1

B) Line 2

C) Line 3

D) Line 4

Q2) Consider the following code snippet:

Public static void reverse(List<? super E> list) { . . . }

Which of the following statements about this code is correct?

A) This is an example of a wildcard with an upper bound.

B) This is an example of a wildcard with a lower bound.

C) This is an example of an unbounded wildcard.

D) This code is illegal.

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) Which of the following classes are used with data in binary form?

I FileInputStream

II FileReader

III RandomAccessFile

A) I

B) I and II

C) I and III

D) II and III

Q2) How many methods are required to implement the Serializable interface?

A) 3

B) 2

C) 1

D) 0

Q3) Given a RandomAccessFile that stores a set of records of class MyData, each needing MyData.RECORD_SIZE bytes for storage, which expression gets the offset to the beginning of the 25<sup>th</sup> record?

A) MyData.RECORD_SIZE * 25

B) MyData.RECORD_SIZE * 24

C) MyData.RECORD_SIZE++

D) MyData.RECORD_SIZE + 25

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

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) When a sleeping thread is interrupted, a(n) ____________________ is generated.

A) ThreadInterruptedException

B) ThreadException

C) ThreadSleepException

D) InterruptedException

Q2) What is likely to be true when thread one is downloading a 1MB file while thread two is downloading another 1MB file?

A) The files download twice as fast as they would if one thread downloaded both files.

B) The files download half as fast as they would if one thread downloaded both files.

C) When thread one is half done, thread two is about half done.

D) The faster thread will interrupt the other thread.

Q3) Insert the statement that would start the following thread.

Thread firstThread = new Thread(myRunnable);

A) firstThread.run();

B) firstThread.start();

C) run();

D) start();

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) Suppose you use the URLGet program in Section 21.5 to get a web page from a server that does not exist, such as http://wombat.java/index.html. What will happen?

A) The call to the URL constructor will throw an exception.

B) The call to getResponseCode will throw an exception.

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

D) The call to getInputStream will throw an exception.

Q2) The _________ class makes it easy to fetch a file from a web server.

A) FileConnection

B) ServerConnection

C) ClientConnection

D) URLConnection

Q3) To close a connection, which of the following statements can you use?

A) URL u = new URL("http://www.yahoo.com");

URLConnection conn = u.close();

B) URL u = new URL(str);

URLConnection conn = new URLConnection(u);

C) URL u = new URL(str);

URLConnection conn = u.closeURLConnection();

D) There is no need to close the connection.

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 following command will compile a Java program called TestDB:

A) java TestDB.class

B) java TestDB.java

C) javac TestDB.java

D) javac TestDB.class

Q2) In SQL, the _____________ command is used to issue queries that do not modify the database.

A) APPEND

B) UPDATE

C) MODIFY

D) SELECT

Q3) In SQL, ____ is used to test for equality.

A) EQUAL

B) ==

C) =

D) EQUALS

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) In XML, a DTD is introduced with the ___________ declaration.

A) FIXED

B) REQUIRED

C) IMPLIED

D) DOCTYPE

Q2) An element that is declared as _______ in a DTD may not have any children.

A) PCDATA

B) ELEMENT

C) NULL

D) EMPTY

Q3) Which of the following statements is correct?

A) In XML, every start-tag must have a matching end-tag.

B) XML files are readable by computer programs but not by humans.

C) Attribute values need not be enclosed in quotes.

D) An element cannot contain mixed content.

Q4) The XML encoding for the ">" character is:

A) &gr;

B) &greaterThan;

C) &gt;

D) &lt;

Page 25

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) The user interface of a web application is displayed in a ______.

A) protocol

B) server browser

C) web browser

D) web server

Q2) Which of the following statements is correct?

A) A server with a JSF container such as GlassFish manages a pool of database connections.

B) JSF tags use XML syntax but the / before the closing angle bracket is not required.

C) JSF tags are case insensitive.

D) A JSF page cannot contain XML tags.

Q3) Both Swing and JSF handle the tedious details of capturing user input, but JSF

A) is a client application.

B) hides high-level details.

C) handles form-posting events.

D) paints pixels in a frame.

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