

Java Programming Test Bank
Course Introduction
Java Programming introduces students to the fundamentals of programming using the Java language, a powerful, versatile, and widely-used platform for developing applications. The course covers essential topics including object-oriented programming principles, data types, control structures, classes, inheritance, polymorphism, exception handling, and file I/O. Students also gain experience with graphical user interfaces, basic algorithms, and collections. Through hands-on projects and exercises, learners build practical skills in problem-solving, debugging, and software development, preparing them for advanced programming courses or professional environments where Java expertise is required.
Recommended Textbook
Java Foundations 3rd Edition by John Lewis
Available Study Resources on Quizplus
16 Chapters
639 Verified Questions
639 Flashcards
Source URL: https://quizplus.com/study-set/3997

Page 2

Chapter 1: Introduction
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80262
Sample Questions
Q1) Write a short Java program that outputs your name, your major, and your birthday on three different lines.
Answer: 11edd9cc_2d01_9f13_84e8_134dfbf1e8f5_TB2841_00
Q2) In order for a program to run on a computer, it must be expressed in ______________________.
A) an assembly language
B) a machine language
C) a high-level language
D) an object-oriented language
E) a fourth generation language
Answer: B
Q3) Which of the following is not a valid Java identifier?
A) answer_7
B) highest$
C) anExtremelyLongIdentifierIfYouAskMe
D) 2ndlevel
E) thirdNumber
Answer: D
Q4) Write an application that prints the first few lines of a song (your choice).
Answer: 11edd9cc_5a45_7376_84e8_afca069acf96_TB2841_00
Page 3
To view all questions and flashcards with answers, click on the resource link above.

Chapter 2: Data and Expressions
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80257
Sample Questions
Q1) Consider the expression: result = 12 + 5 / 2; What value stored in result after this line is executed?
A) 14.5
B) 8.5
C) 9
D) 14
E) this will result in a compiler error
Answer: D
Q2) Consider the following snippet of code: System.out.println("30 plus 25 is " + 30 + 25);
What is printed by this line?
A) 30 plus 25 is 55
B) 30 plus 25 is 30
C) 30 plus 25 is 25
D) 30 plus 25 is 3025
E) this snippet of code will result in a compiler error
Answer: D
Q3) How are primitive data types and object data types related?
Answer: Object types are more complex data types, and they are generally made up of primitive data types.
To view all questions and flashcards with answers, click on the resource link above.
Page 4

Chapter 3: Using Classes and Objects
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80255
Sample Questions
Q1) The ________________ operator is used to instantiate an object.
A) static
B) new
C) +
D) -
E) none of the above
Answer: B
Q2) Explain what it means for a String object to be immutable. Are there any workarounds for this?
Answer: String objects are immutable, meaning that once a String object is created, its value cannot be lengthened or shortened, nor can any of its characters change. However, there are several methods in the String class that return new modified String objects. By reassigning the original reference to the result of calling one of these methods, we can effectively change the value of a String object.
Q3) The Math class is part of the java.lang package.
A)True
B)False
Answer: True
To view all questions and flashcards with answers, click on the resource link above.

Chapter 4: Conditionals and Loops
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80254
Sample Questions
Q1) Every if statement requires an associated else statement, but not every else statement requires an associated if statement.
A)True
B)False
Q2) What is wrong with the following snippet of code? Rewrite it so it produces the correct output.
if(a < b)
if(a == c)
System.out.println( a < b and a == c ); else
System.out.println( a is not less than b );
Q3) Using a while loop, write a code fragment that computes the sum of the first n natural numbers (i.e. 1, 2, 3, 4, ... n), where n is an integer variable already defined in the program.
Q4) Write a do loop that verifies that the user enters an odd value. You may assume that a Scanner object called input has already been created.
Q5) A Scanner object can use delimiters other than a space.
A)True B)False
To view all questions and flashcards with answers, click on the resource link above. Page 6

Chapter 5: Writing Classes
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80253
Sample Questions
Q1) Variables that are declared as static are shared among all instances of a class.
A)True
B)False
Q2) Aggregation is sometimes described as a has-a relationship.
A)True
B)False
Q3) Explain why a static method cannot refer to an instance variable.
Q4) A method that has multiple definitions is an __________________ method.
A) overloaded
B) overridden
C) overlooked
D) overclocked
E) none of the above
Q5) Methods that can be called directly through the class name and do not need to have an object instantiated are called _________________.
A) final
B) public
C) static
D) private
E) none of the above
To view all questions and flashcards with answers, click on the resource link above. Page 7

Chapter 6: Graphical User Interfaces
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80252
Sample Questions
Q1) Which of the following components allows the user to enter typed input from the keyboard.
A) check boxes
B) radio buttons
C) sliders
D) combo boxes
E) none of the above
Q2) Layout managers determine how components are visually presented.
A)True
B)False
Q3) Write a short class that represents a panel with a single slider that has values from 0 to 250, with large tick marks in increments of 50 and small tick marks in increments of 10.
Q4) Should a component ever be disabled? Why or why not?
Q5) Explain the difference between check boxes and radio buttons.
Q6) The grid layout organizes components into a grid of rows and columns, and also allows components to span more than one cell.
A)True
B)False
Q7) What is the difference between a mnemonic and a tool tip?
Page 8
To view all questions and flashcards with answers, click on the resource link above.

Chapter 7: Arrays
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80251
Sample Questions
Q1) Write a method that accepts an array of integers as a parameter and returns the sum of all of the integers in the array.
Q2) Write a method called doubleSize that accepts an integer array as a parameter and returns a reference to a new integer array that is twice as long and contains all of the elements of the first array in the same positions.
Q3) Which of the following array declarations are invalid?
A) int[] grades = new int[5];
B) int grades[] = new int[5];
C) int[] grades = { 91, 83, 42, 100, 77 };
D) all of the above are valid
E) none of the above are valid
Q4) Multi-dimensional arrays that contain arrays of different lengths in any one dimension are called _________________.
A) ragged arrays
B) static arrays
C) two-dimensional arrays
D) constant arrays
E) overloaded arrays
Q5) Explain how arrays are passed to methods as parameters.
To view all questions and flashcards with answers, click on the resource link above. Page 9

Chapter 8: Inheritance
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80250
Sample Questions
Q1) A class declared as final _________________________________ .
A) cannot be changed.
B) cannot have subclasses.
C) cannot have superclasses.
D) has several abstract methods.
E) cannot be used in a program.
Q2) What is a shadow variable?
Q3) What does it mean for a class to be declared as final? What does it mean for a method to be declared as final?
Q4) Explain how a subclass can can access its parent classes private instance variables and methods.
Q5) Draw a hierarchy of people at a University.
Q6) Inheritance should not be considered in the software design process. A)True B)False
Q7) Explain why inheritance is useful.
Q8) Methods and variables declared as private in a parent class cannot be accessed in a child class.
A)True
B)False
To view all questions and flashcards with answers, click on the resource link above. Page 10
Chapter 9: Polymorphism
Available Study Resources on Quizplus for this Chatper
39 Verified Questions
39 Flashcards
Source URL: https://quizplus.com/quiz/80249
Sample Questions
Q1) Suppose you are implementing the comparable interface in a class representing a Person, where the ordering is based on the age of the person. Write a compareTo method for this class. You may assume that there is an instance variable called age and a method called getAge.
Q2) Let Dog be a subclass of Animal, and suppose Animal has a method called speak() that is overridden in the Dog class. Consider the following code. Animal spot = new Dog(); Spot.speak();
Which of the following is true?
A) This code will result in a compile-time error.
B) This code will result in a run-time error.
C) The speak method defined in the Animal class will be called.
D) The speak method defined in the Dog class will be called.
E) The speak method will not be called at all.
Q3) Give an example of a class that implements the Iterator interface.
Q4) The next method of the Iterator interface returns a reference to the next element in a collection and removes it.
A)True
B)False

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

Chapter 11: Recursion
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80260
Sample Questions
Q1) Describe a recursive solution to determine whether a String object is a palindrome. You may assume that the string only contains lower case characters (i.e. no numbers, spaces, punctuation, etc). Hint: It may be easiest to describe your solution using pseudocode.
Q2) Write the recursive definition of the factorial of a number.
Q3) Write a recursive method that computes the product of all of the even integers less than or equal to n.
Q4) In the Towers of Hanoi puzzle there are __________________ disks of different diameters.
A) 2
B) 3
C) 4
D) 5
E) The Towers of Hanoi puzzle can include any number of disks of different diameters.
Q5) Describe the Towers of Hanoi puzzle.
Q6) Recursion is necessary.
A)True
B)False
Q7) Write a recursive method that computes the sum of the first n integers.
Page 12
To view all questions and flashcards with answers, click on the resource link above.

Chapter 10: Exceptions
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80261
Sample Questions
Q1) Unchecked exceptions must be caught or propogated, or a program will not compile.
A)True
B)False
Q2) A throw statement is used to begin exception propagation.
A)True
B)False
Q3) Write a short snippet of code that converts the first element of the String[] args array to an integer. It should catch an exception and print out a message if the first element cannot be converted to an integer.
Q4) A(n) ____________________ can be used to find the exact line where an exception was thrown during program execution.
A) interface
B) call-stack trace
C) try block
D) catch block
E) none of the above
Q5) What is the difference between a checked exception and an unchecked exception?
Q6) What is exception prorogation, and how does it work in Java?
To view all questions and flashcards with answers, click on the resource link above. Page 13

Chapter 12: Searching and Sorting
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80259
Sample Questions
Q1) The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted.
A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort
Q2) Which of the following algorithms has a time complexity of O(log<sub>2</sub> n)?
A) insertion sort
B) selection sort
C) bubble sort
D) linear search
E) binary search
Q3) A __________________ search looks through the search pool one element at a time.
A) binary
B) clever
C) insertion
D) selection
E) linear
Q4) Explain what O(1) means.
To view all questions and flashcards with answers, click on the resource link above. Page 14

Chapter 13: Trees
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80258
Sample Questions
Q1) Suppose we are implementing a binary tree as a linked structure of BinaryTreeNode objects. Write a method that will print out all of the nodes of tree via an inorder traversal. You may assume that the class has a reference to a BinaryTreeNode object called root. In addition, your method may take a reference to a BinaryTreeNode object as a parameter.
Q2) Since trees are nonlinear structures, it is impossible to implement them using an array.
A)True
B)False
Q3) What is an internal node in a tree?
Q4) What are the leaves of a tree?
Q5) Which of the following traversals visits the root after visiting the left and right subtrees?
A) Preorder
B) Inorder
C) Postorder
D) Level-order
E) none of the above
Q6) How many leaves will be contained in a full binary tree of height 5?
Q7) What is a decision tree?
To view all questions and flashcards with answers, click on the resource link above. Page 15

Chapter 14: Introduction to Collections and Stacks
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80248
Sample Questions
Q1) A queue is a FIFO structure.
A)True
B)False
Q2) The peek operation on a stack returns a reference to the element at the bottom of the stack.
A)True
B)False
Q3) In an ideal implementations of a stack and a queue, all operations are
A) O(1)
B) O(n)
C) O(n log n)
D) O(n<sup>2</sup>)
E) it depends on the operation
Q4) Write a push method for a stack implemented as a linked structure. You may assume that the implementation has the top element of the stack referenced by a LinearNode<T> reference top and that an integer variable count keeps track of the number of elements in the stack.
Q5) List the five basic operations on a stack.
Q6) What is wrong with the java.util.Stack implementation of a stack?
Page 16
To view all questions and flashcards with answers, click on the resource link above.

Chapter 15: Heaps and Priority Queues
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80247
Sample Questions
Q1) Explain how an element is added to a heap.
Q2) A heap sort sorts elements by constructing a heap out of them, and then removing them one at a time from the root.
A)True
B)False
Q3) If a binary search tree becomes unbalanced after an element is added, it is sometimes possible to efficiently rebalance the tree by ___________________ .
A) using left and right rotations
B) selecting a leaf node to use as a new root
C) reconstructing the tree from scratch
D) all of the above
E) it is impossible to rebalance a tree efficiently
Q4) Draw a binary search tree that results from inserting the following elements: 12, 16, 9, 1, 15, 13
Q5) Describe the steps involved in performing a right rotation on a node in a binary search tree.
Q6) Explain how heap sort works.
Q7) What is a heap?
Q8) What is the inorder successor of a node in a binary search tree?
To view all questions and flashcards with answers, click on the resource link above. Page 17

Chapter 16: Graphs
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/80256
Sample Questions
Q1) An adjacency matrix is one approach to implementing a graph that uses a two-dimensional array.
A)True B)False
Q2) In an undirected graph, an edge of the form (A, B) is the same as an edge of the form (B, A).
A)True B)False
Q3) Consider the following undirected graph. vertices: 1, 2, 3, 4, 5 edges: (1,2),(3,4), (2,4), (2, 3), (3,5), (4,5)
Give a spanning tree for this graph.
Q4) A breadth-first traversal of a graph uses which of the following data structures?
A) binary search tree
B) stack
C) queue
D) array
E) none of the above
Q5) Write out all of the edges in a complete graph on 4 vertices.
To view all questions and flashcards with answers, click on the resource link above. Page 18