Skip to main content

Java Programming Final Exam - 2169 Verified Questions

Page 1


Java Programming

Final Exam

Course Introduction

Java Programming is an introductory course designed to teach students the fundamentals of computer programming using the Java language. The course covers core concepts such as variables, data types, operators, control structures (including loops and conditionals), arrays, object-oriented programming principles, and exception handling. Students will also gain practical experience developing Java applications, working with classes and objects, and utilizing key libraries and tools. By the end of the course, participants will be able to design, write, and debug Java programs, laying the groundwork for more advanced programming topics and software development projects.

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) Computers are machines that

A) design computer programs.

B) execute programs.

C) carry out a very narrow range of tasks.

D) are imprecise and slow.

Answer: B

Q2) Computer programming is

A) the speed with which a computer operates.

B) the collection of peripheral devices connected to a computer.

C) the storage of data in the form of words and pictures.

D) the act of designing and implementing a computer program.

Answer: D

Q3) The ENIAC computer burned out transistors at the rate of

A) ten per day

B) one hundred per day

C) several per day

D) None - it used vacuum tubes

Answer: B

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

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) Assuming that the user inputs "Joe" at the prompt, what is the output of the following code snippet?

Public static void main(String[] args)

{ System.out.print("Enter your name "); String name; Scanner in = new Scanner(System.in); Name = in.next();

Name += ", Good morning"; System.out.print(name);

}

A) The code snippet does not compile because the += operator cannot be used in this context.

B) Joe, Good morning C) , Good morning

D) Joe

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

Int s1 = 20; If (s1 <= 20)

{ System.out.print("1"); } If (s1 <= 40)

{ System.out.print("2"); }

If (s1 <= 20)

{ System.out.print("3"); }

A) 1

B) 2

C) 3

D) 123

Answer: D

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) Given the following code snippet, what should we change to have 26 alphabet characters in the string str?

String str = "";

For (char c = 'A'; c < 'Z'; c++)

{ Str = str + c; }

A) int c = 'A'

B) str = c + str;

C) c <= 'Z'

D) Must change to use a do loop

Q2) Which of the loop(s) test the condition after the loop body executes?

I. for loop

II. while loop III. do loop

A) I only

B) II only

C) III only

D) II and III

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

Public static void doubleAmount(int intvalue)

{ Intvalue = 2 * intvalue;

} Public static void main(String[] args)

{

Int principalAmt = 2000; System.out.println(doubleAmount(principalAmt));

}

A) 2000

B) 4000

C) 0

D) Compilation error

Q2) Which of the following is not legal in a method definition?

A) Multiple parameter variables

B) Parameter variable data types

C) One return value

D) Multiple return values

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

Int[][] numarray =

{

{ 8, 7, 6 },

{ 0, 0, 0 }

};

System.out.print(numarray[0][0]);

System.out.print(numarray[1][0]);

A) 00

B) 87

C) 80

D) 08

Q2) Which one of the following statements is a valid initialization of an array named somearray of ten elements?

A) int[] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

B) int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

C) int[10] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

D) int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

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 and write to an output file named dataOut.txt.

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

{

String inputFileName = "dataIn.txt";

String outputFileName = "dataOut.txt";

File inputFile = _________________;

Scanner in = new Scanner(inputFile)

) . .

}

A) new File(inputFileName)

B) new File(outputFileName)

C) new File(inputFile)

D) new File(System.in)

Q2) Which of the following objects should be used for reading from a text file?

A) Scanner

B) ReadStream

C) PrintStream

D) ReadFile

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) Insert the missing code in the following code fragment. This fragment is intended to implement a method to get the value stored in an instance variable.

Public class Vehicle

{ Private String model; Private double rpm; )

Return model;

A) public void setModel(String modelName)

B) public void getModel()

C) public String getModel()

D) public String setModel(String modelName)

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

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) To define a class that fulfills the requirements of an interface, the class header should include which of the following?

A) The keyword extends and the name of an abstract method in the interface

B) The keyword extends and the name of the interface

C) The keyword implements and the name of an abstract method in the interface

D) The keyword implements and the name of the interface

Q2) A class from which you cannot create objects is called a/an ____.

A) Abstract class.

B) Concrete class.

C) Non-inheritable class.

D) Superclass.

Q3) Consider the following code snippet:

Int numAxles = 4;

String s = "Number of axles is " + numAxles; Which of the following statements is correct?

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

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

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

D) This code will not compile.

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

Page 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) To respond to a button event, a listener must supply instructions for the ____ method of the ActionListener interface.

A) actionEvent

B) actionPerformed

C) eventAction

D) eventResponse

Q2) How do you specify what the program should do when the user clicks a button?

A) Specify the actions to take in a class that implements the ButtonListener interface.

B) Specify the actions to take in a class that implements the ButtonEvent interface .

C) Specify the actions to take in a class that implements the ActionListener interface.

D) Specify the actions to take in a class that implements the EventListener interface.

Q3) When an event occurs, the event source notifies all associated ____.

A) components

B) panels

C) interfaces

D) event listeners

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) Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the EAST, and component2, which was added to the WEST. Which parts of the JPanel appear?

I North II South III Center IV West

V East

A) I, II

B) I, II, III

C) III, IV and V

D) IV an V

Q2) The JFrame has a content pane with a default BorderLayout manager. Which method allows changing it to a FlowLayout manager?

A) setLayout

B) setFlowLayout

C) assignLayout

D) changeLayout

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) Aggregation denotes that ____.

A) Objects of one class inherit from objects of its superclass.

B) Objects of one class can be inherited by its subclasses.

C) Objects of one class contain references to objects of its superclass.

D) Objects of one class contain references to objects of another class.

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

Q3) The final step of the design phase recommended by the textbook is to ____.

A) Write the documentation of the discovered classes and methods

B) Write the code for each class and all of its methods.

C) Identify the classes and methods that will be required.

D) Create the UML diagrams to represent the classes.

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

}

If line #1 was eliminated from the method, what would be the result when calling getArea?

A) A negative or zero width would cause problems.

B) Nothing - the method would still work correctly.

C) We would lose our only recursive case.

D) A positive width would reduce the correct area by 1.

Q2) What is the purpose of a recursive helper method?

A) Shield the user of the recursive method from the recursive details.

B) Speed up the execution.

C) Eliminate the recursion.

D) Add another base case.

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

Page 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 a call to the Arrays static method binarySearch returns a value of -10, what can be concluded?

I the element is not in the array

II the element is at index 10

III the element can be inserted at index 9

A) I

B) II

C) III

D) I and III

Q2) Find the simplest order of growth of the following expression: n<sup>3</sup> + log(n<sup>5</sup>).

A) (n<sup>3</sup>)

B) (n<sup>3</sup>+ log(n))

C) (log(n<sup>5</sup>))

D) (n<sup> </sup>+ log(n))

Q3) How large does n need to be so 0.3n<sup>2</sup> is greater than 2.5n - 3?

A) 3

B) 5

C) 7

D) 9

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) Which method is NOT part of the ListIterator generic class?

A) hasNext

B) hasMore

C) hasPrevious

D) add

Q2) What can a generic class be parameterized for?

A) properties

B) iterators

C) type

D) methods

Q3) Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly insert an element into myMap?

A) myMap.insert(3, "apple");

B) myMap.put(3, "apple");

C) myMap.push(3, "apple");

D) myMap.add(3, "apple");

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

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) If the current size of an array list is less than the length of the buffer, adding an element at the end of an array list takes ____ time.

A) O(n)

B) O(1)

C) O(log(n))

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

Q2) Which statement about handling collisions in a hash table using the open addressing technique is correct?

A) A colliding element will always be contiguous to the location in which it would normally be placed.

B) To find an element, you must search from the hash code location until a match or an element with a different hash code is found.

C) To remove an element, you simply empty the slot at which you find it.

D) There may be some elements with different hash codes that lie on the same probing sequence.

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) In a binary search tree, where the root node data value = 45, what do we know about the values of all the descendants in the right subtree of the root?

A) the root's right child value > 45, but the left child of the root's right child key is < 45

B) some values will be > 45, but there may be a few values < 45

C) approximately half the values are < 45, the other half are > 45

D) all will be > 45

Q2) You wish to traverse a binary search tree in sorted order using preorder traversal. Arrange the following actions in the correct order to accomplish this.

I Print the right subtree recursively

II Print the root

III Print the left subtree recursively

A) I, II, III

B) III, II, I

C) II, III, I

D) III, I, II

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

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() { . . . } }

Which of the following choices is a specific type of the generic Box class?

A) Box&lt;int&gt;

B) Box&lt;E&gt;

C) Box&lt;Double&gt;

D) Box

Q2) To maintain compatibility with pre-generic Java, type parameters are replaced by ordinary types called ____.

A) primitives

B) raw types

C) Object

D) generics

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) In which package are most classes for file processing found?

A) java.file

B) java.inputoutput

C) java.io

D) java.stream

Q2) Which class is used for input of text data?

A) Reader

B) Writer

C) InputStream

D) OutputStream

Q3) If we read a byte and the value represents an international character equal to 133 using an InputStream object, what is true about the int value we will read?

A) It will be 133.

B) It will be -133.

C) It will be some negative value.

D) It will be some positive value.

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) To start a thread, you should first construct an object from a class that implements the ____________ interface.

A) Thread

B) Threadable

C) Run

D) Runnable

Q2) Which are ways that a thread can be blocked? I when it is sleeping II waiting for a lock to be available III waiting after calling the await method

A) I

B) I and II

C) I and III

D) I, II and III

Q3) A waiting thread is blocked until another thread calls ____ on the condition object for which the thread is waiting.

A) await

B) signalAll

C) interrupt

D) lock

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 does the following if statement do?

If (code == HttpURLConnetion.HTTP_OK)

A) It checks if the code is 200.

B) It checks if the code is 404.

C) It checks if the connection is still connected.

D) It checks if there is HTTP.

Q2) The HTTP response code 404 means _______________.

A) the response is successful.

B) the page is found successfully.

C) the page was not found.

D) the connection is lost.

Q3) For the server to execute the run method in a separate thread for each client, the application program needs to implement the _____ interface.

A) Running

B) Runtime

C) Server

D) Runnable

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 outcome of a SQL query is a ____________________.

A) table

B) view of the data

C) list

D) subquery

Q2) When you are done with a Statement object, _______.

A) you should close it and you must close the associated result set as well.

B) you should not close it and should not close the associated result set.

C) you should close it and that automatically closes the associated result set.

D) you should only close the associated result set.

Q3) If your program needs to look at several result sets at the same time, _____.

A) you need to create multiple Statement objects.

B) you can reuse the Statement or PreparedStatement objects

C) you should close the ResultSet before creating a new one.

D) you are not able to see several sets at the same time.

Q4) An example of a desktop database is:

A) Oracle

B) MS Access

C) Apache Derby

D) MySQL

Page 24

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

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) What package will you use to import DocumentBuilder?

A) javax.swing.DocumentBuilder

B) javax.xml.DocumentBuilder

C) javax.parsers.DocumentBuilder

D) javax.xml.parsers.DocumentBuilder

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) Elements describe how to interpret attributes.

B) In XML, attribute values must be enclosed in quotes.

C) Mixed content allows you to have control over the order in which elements appear.

D) You should always use mixed content for elements that describe data sets.

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

25

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) Where does the application program of a web application reside?

A) On the client server.

B) On the web server.

C) On the client side.

D) On the browser client.

Q2) The _______ converts a JSF page to an HTML page.

A) JSF translator

B) JSF compiler

C) JSF container

D) HTML converter

Q3) Swing differs from JSF in that it ________.

A) handles form-posting events.

B) paints pixels in a frame.

C) paints by emitting HTML code.

D) hides high-level details.

Q4) To query a database, a JavaBean needs a(n) ____________ object.

A) Table

B) Connection

C) Bean

D) HTML

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

Turn static files into dynamic content formats.

Create a flipbook