Java Programming Textbook Exam Questions - 820 Verified Questions

Page 1


Java Programming

Textbook Exam Questions

Course Introduction

This course introduces students to the fundamentals of Java programming, focusing on problem-solving, algorithm development, and basic software design. Students will learn core Java concepts including data types, control structures, object-oriented programming principles, exception handling, and file input/output. Through hands-on labs and projects, students will develop skills in writing, testing, and debugging Java applications, while gaining a solid foundation for further study in computer science or software development.

Recommended Textbook

Java Software Solutions 8th Edition by John Lewis

Available Study Resources on Quizplus

13 Chapters

820 Verified Questions

820 Flashcards

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

2

Chapter 1: Introduction

Available Study Resources on Quizplus for this Chatper

65 Verified Questions

65 Flashcards

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

Sample Questions

Q1) Objects are defined by a class that describes the characteristics common to all instances of the class.

A)True

B)False

Answer: True

Q2) Polymorphism is the idea that we can refer to multiple types of related objects in consistent ways.

A)True

B)False

Answer: True

Q3) When executing a program, the processor reads each program instruction from A) secondary memory (storage)

B) the Internet

C) registers stored in the processor

D) main memory

E) could be any of these

Answer: D

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

Page 3

Chapter 2: Data and Expressions

Available Study Resources on Quizplus for this Chatper

77 Verified Questions

77 Flashcards

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

Sample Questions

Q1) Which library package would you import to use the class Random?

A) java.beans

B) java.io

C) java.lang

D) java.text

E) java.util

Answer: E

Q2) If you want to output the text "hi there", including the quote marks, which of the following could do that?

A) System.out.println("hi there");

B) System.out.println(""hi there"");

C) System.out.println("\"hi there");

D) System.out.println("\"hi there\"");

E) none, it is not possible to output a quote mark because it is used to mark the beginning and ending of the String to be output

Answer: D

Q3) A double is wider than a float and a float is wider than an int.

A)True

B)False

Answer: True

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

58 Verified Questions

58 Flashcards

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

Sample Questions

Q1) When comparing any primitive type of variable, == should always be used to test to see if two values are equal.

A)True

B)False

Answer: False

Q2) You may apply the prefix and postfix increment and decrement operators to instances of the Integer class.

A)True

B)False

Answer: False

Q3) A containment hierarchy is

A) a collection of relationships among panels, all at the same level

B) a nested collection of relationships among containers

C) a nested collection of relationships among applets

D) a collection of relationships among frames, usually at different levels

E) none of the above

Answer: B

Q4) Write a statement using a method to guarantee that the initial will be a capital letter. Answer: firstInitial = firstInitial.toUpperCase( );

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

Chapter 4: Writing Classes

Available Study Resources on Quizplus for this Chatper

56 Verified Questions

56 Flashcards

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

Sample Questions

Q1) An Employee will have a name, social security number, position, and hourly wages. Define the instance data for this class.

Q2) Accessors and mutators provide mechanisms for controlled access to a well-encapsulated class.

A)True

B)False

Q3) While multiple objects of the same class can exist, in a given program there can be only one version of each class.

A)True

B)False

Q4) Add a constructor to class Box for a cube, which has only 1 parameter, side.

Q5) The interface of a class is based on those data instances and methods that are declared public.

A)True

B)False

Q6) Consider the "Push Me!" program described in section 4.7. As given the push counter starts at zero and is incremented each time the "Push Me!" button is pressed. Let's say that you want to add a class called ResetListener that resets the count to zero. Write the ResetListener class.

Page 6

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

Chapter 5: Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

37 Verified Questions

37 Flashcards

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

Sample Questions

Q1) The statement { } is a legal block.

A)True

B)False

Q2) The expression (!done && x <= y) is True.

A)True

B)False

Q3) If a break occurs within the innermost loop of a nested loop that is three levels deep

A) when the break is encountered just the innermost loop is "broken"

B) when the break is encountered, all loops are "broken" and execution continues from after the while statement (in our example)

C) when the break is encountered, all but the outermost loops are broken, and execution continues from the next iteration of the while loop (in our example)

D) this is a syntax error unless there are break or continue statements at each loop level E) none of the above

Q4) The expression (done | | s.compareTo(t) < 0) is True.

A)True

B)False

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

Chapter 6: More Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

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

Sample Questions

Q1) The following for-loop is odd in that the loop increment value changes during iterations of the loop. Determine the number of times the loop iterates and the final value of j after the loop terminates.

int k = 0; for (j = 0; j < 20; j += k) k++;

Q2) A switch statement must have a default clause. A)True B)False

Q3) The following nested loop structure will execute the inner most statement (x++) how many times?

For (int j = 0; j < 100; j++)

For (int k = 100; k > 0; k--)

X++;

A) 100

B) 200

C) 10,000

D) 20,000

E) 1,000,000

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

Page 8

Chapter 7: Object-Oriented Design

Available Study Resources on Quizplus for this Chatper

76 Verified Questions

76 Flashcards

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

Sample Questions

Q1) Defining formal parameters requires including each parameters type.

A)True

B)False

Q2) If a programmer follows the four phases of program development as intended, which of the four phases should require the least amount of creativity?

A) software requirements

B) software design

C) software implementation

D) software testing

E) none of the above, all four levels would require equal creativity

Q3) A bad programming habit is to build an initial program and then spend a great deal of time modifying the code until it is acceptable. This is known as

A) the prototyping approach

B) the waterfall model

C) iterative development

D) the recursive approach

E) the build-and-fix approach

Q4) Why was the Y2K problem a problem of software maintenance and not a problem of software testing?

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

Chapter 8: Arrays

Available Study Resources on Quizplus for this Chatper

70 Verified Questions

70 Flashcards

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

Sample Questions

Q1) Assume xArray and yArray are equal length arrays of int values storing num items (num is also an int). Write a paint method for an Applet that will draw a Polygon shape using this information. Assume xArray, yArray and num are all instance data of the Applet.

Q2) To declare a three-dimensional int array called threeD, which of the following would you use?

A) int[3] threeD;

B) int[ , , ] threeD;

C) int[ ][ ][ ] threeD;

D) int [ [ [ ] ] ] threeD;

E) int[ ] threeD[3];

Q3) So long as one is only accessing the elements of an ArrayList, its efficiency is about the same as that of an array. It's only when one begins to insert or remove elements towards the front portion of an ArrayList that its efficiency deteriorates.

A)True

B)False

Q4) Demonstrate how the following array is sorted using Selection Sort. Show the array after each pass of the outer loop. [16, 3, 12, 13, 8, 1, 18, 9]

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

Chapter 9: Inheritance

Available Study Resources on Quizplus for this Chatper

71 Verified Questions

71 Flashcards

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

Sample Questions

Q1) A variable declared to be of one class can later reference an extended class of that class. This variable is known as

A) protected

B) derivable

C) cloneable

D) polymorphic

E) none of the above, a variable declared to be of one class can never reference any other type of class, even an extended class

Q2) In what manners are Timer objects similar to and different from other GUI components?

Q3) An applet implements MouseListener, and has int instance data x and y. These variables will be the (X, Y) coordinates of where the mouse is clicked. Every time the mouse is clicked, draw a 40x40 Oval centered around x and y. Write the mouseClicked and paint methods to draw the Oval every time the mouse is clicked.

Q4) The assignment statement p = d; is legal even though p is not a Dog.

A)True

B)False

Q5) Explain the difference between implementing an interface and a derived class.

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

Chapter 10: Polymorphism

Available Study Resources on Quizplus for this Chatper

70 Verified Questions

70 Flashcards

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

Sample Questions

Q1) Both the Insertion Sort and the Selection Sort algorithms have efficiencies on the order of ________ where n is the number of values in the array being sorted.

A) n

B) n * log n

C) n²

D) n³

E) Insertion sort has an efficiency of n and Selection Sort has an efficiency of n²

Q2) Which of the following GUI components would you use to allow the user to select between a range of numeric alternatives?

A) JComboBox

B) JList

C) JSlider

D) JScrollPane

E) JOptionPane

Q3) A polymorphic reference can refer to different types of objects over time.

A)True

B)False

Q4) Is it possible to use both overloading and overriding in the same method?

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

Page 12

Chapter 11: Exceptions

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) Which of the following is not True of the RuntimeExceptions class?

A) All RuntimeExceptions throw checked exceptions

B) All RuntimeExceptions are Throwable objects

C) RuntimeException has child classes ArithmeticException and NullPointerException

D) RuntimeException objects are not Error objects

E) All of the above are True

Q2) Scroll panes automatically will scroll vertically, but special code needs to be used if a scroll pane is to scroll horizontally.

A)True

B)False

Q3) Rewrite the following code using try and catch statements, catching any exceptions that might be thrown. Assume keyboard is a BufferedReader. for (j=0;j&lt;limit;j++)

{ x = Integer.parseInt(keyboard.readLine( )); y[j] = 1 / x; }

Q4) Explain how you would use a Timer to create animation in a JLabel.

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

13

Chapter 12: Recursion

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) Describe how to solve the Towers of Hanoi problem using 4 disks (that is, write down move for move how to solve the problem).

Q2) The following method correctly multiplies two ints so long as both are non-negative: public int mpy(int a, int b)

{ return (b > 0) ? a + mpy(a, b-1) : 0;

}

A)True

B)False

Q3) Rewrite the following iterative method as a recursive method that returns the same String.

public String listOfNumbers( ) { String s = ""; for (j = 1; j<10; j++) s += j; return s;

}

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

Page 14

Chapter 13: Collections

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) What changes would have to be made to the BookNode class in order to define it as its own class outside of BookList?

Q2) Rather than defining BookNode inside of BookList, another option is to define BookNode as a separate class and import it into BookList. Why might we do this rather than define BookNode inside of BookList?

Q3) Draw this structure.

Q4) Which of the following is considered an Abstract Data Type?

A) array

B) reference variable

C) any of the primitive types (e.g., int, double, char)

D) vector

E) all of the above

Q5) The linked list is superior to the array in all ways when it comes to implementing a list.

A)True

B)False

Q6) Queues and Stacks can be implemented using either arrays or linked lists.

A)True

B)False

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

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.