Beginning Java Programming Exam Practice Tests - 820 Verified Questions

Page 1


Beginning Java Programming Exam Practice Tests

Course Introduction

Beginning Java Programming introduces students to the foundational concepts of computer programming using the Java language. The course covers the basics of writing, compiling, and executing Java programs, including fundamental syntax, data types, control structures, arrays, methods, and object-oriented principles such as classes and objects. Students will develop problem-solving skills through hands-on coding exercises and projects, preparing them to design, implement, and debug simple Java applications. This course is ideal for those new to programming or software development.

Recommended Textbook

Java Software Solutions Foundations of Program Design 7th Edition by John Lewis

Available Study Resources on Quizplus

13 Chapters

820 Verified Questions

820 Flashcards

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

Page 2

Chapter 1: Introduction

Available Study Resources on Quizplus for this Chatper

65 Verified Questions

65 Flashcards

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

Sample Questions

Q1) There are a number of reserved words in Java that have no current meaning (denoted with an * in figure 1.18). Why?

Answer: Java language designers anticipate introducing these statements in future versions, but have not yet implemented them because they are lower priority, or it has not been decided how they will be implemented or precisely what they will mean.

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

A)True

B)False

Answer: True

Q3) Following Java naming convention, which of the following would be the best name for a class about store customers?

A) StoreCustomer

B) Store Customer

C) storeCustomer

D) STORE_CUSTOMER

E) Store-Customer

Answer: A

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

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/30661

Sample Questions

Q1) Provide three examples of code using assignment statements where one assignment statement would result in a syntax error, one would result in a logical error, and one would result in a run-time error.

Answer: int x = 5.0 / 2.0; // syntax error caused by right side providing a double and the left side wants an int double x = (intValue1 + intValue2) / 2; // logical error caused by not casting the division as a double int x = 5 / (y - y); // run-time error caused by division by 0 when y - y is evaluated

Q2) You specify the shape of an oval in a Java applet by defining the oval's

A) arc locations

B) center and radius

C) bounding box

D) foci

E) none of the above, it is not possible to draw an oval in a Java applet

Answer: C

Q3) Write an output statement which will output the following characters exactly as shown: / ' \" / ' \

Answer: System.out.println("/ \ ' \ \ \" / \ ' \ \ ");

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/30662

Sample Questions

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

Q2) These two ways of setting up a string yield identical results:

a) String string = new String("string");

b) String string = "string";

A)True

B)False Answer: True

Q3) The printf method within System.out is designed to ease the conversion of legacy C code into Java.

A)True

B)False Answer: True

Q4) These two ways of setting up a String yield identical results:

a) String string = new String("123.45");

b) String string = "" + 123.45; A)True

B)False Answer: True

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/30663

Sample Questions

Q1) What visibility modifiers would you use for the methods that move the elevator up one floor, move the elevator down one floor, that request the elevator, and that start the elevator moving?

Q2) Java methods can return only primitive types (int, double, float, char, boolean, etc).

A)True

B)False

Q3) What are the objects needed in order to create a Java GUI (graphical user interface)?

A) components

B) events

C) listeners

D) all of the above

E) only classes from AWT and/or Swing are needed

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

Q5) Write the constructor, which is passed the player's name and position.

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

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

Chapter 5: Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

37 Verified Questions

37 Flashcards

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

Sample Questions

Q1) Of the following if statements, which one correctly executes three instructions if the condition is True?

A) if (x < 0) a = b * 2;

Y = x;

Z = a - y;

B) { if (x < 0)

A = b * 2;

Y = x;

Z = a - y;

C) if { (x < 0) a = b * 2;

Y = x;

Z = a - y ;

D) if (x < 0) {

A = b * 2;

Y = x;

Z = a - y;

E) B, C and D are all correct, but not A

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

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/30665

Sample Questions

Q1) Write a paint method to draw out an American flag. The flag will comprise a blue square in the upper left corner and 13 red and white stripes, starting with red, and alternating. 6 of the 13 stripes appear to the right of the blue square and the last 7 stripes appear beneath the blue square extending as far right as the other stripes. Use a for-loop to draw the stripes. Do not try to draw any stars in the blue square.

Q2) How many times will the following loop iterate?

Int x = 10; Do { System.out.println(x);

X--;

} while (x > 0);

A) 0 times

B) 1 time

C) 9 times

D) 10 times

E) 11 times

Q3) Write a set of code that outputs all of the int values between 1 and 100 with 5 values per line, and each of those 5 values spaced out equally. Use a single for-loop to solve this problem.

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/30666

Sample Questions

Q1) Any class can implement an interface, but no classes can implement more than a single interface.

A)True

B)False

Q2) Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces

B) modulary

C) information hiding

D) code reuse

E) correctness

Q3) Write a static method that is passed two ChessPieces and determines if the two pieces are owned by the same player. It should return True or false.

Q4) A border can be put around any Swing component with the exception of a JButton and JScrollPane component.

A)True

B)False

Q5) In what way is black-box testing better than glass-box testing? In what way is glass-box testing better than black-box 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/30667

Sample Questions

Q1) In a two-dimensional array, both dimensions must have the same number of elements, as in[10][10].

A)True

B)False

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

Q3) Write code to create a JPanel with 4 JCheckBox GUI components and two JLabels for output, one that says "Current cost is" and the other that outputs the computed cost based on which of the food items has been selected.

Q4) Write a code fragment to create a two-dimensional 10x10 array and initialize every element to be the value of i * j where i and j are the two indices (for instance, element [5][3] is 5 * 3 = 15).

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

Chapter 9: Inheritance

Available Study Resources on Quizplus for this Chatper

71 Verified Questions

71 Flashcards

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

Sample Questions

Q1) An Applet implements MouseMotionListener. Write the mouseMoved and paint methods for an applet that will display the location of the mouse as an (x, y) coordinate. The output should be given at location (10, 10) of the applet no matter where the mouse is.

Q2) Inheritance through an extended (derived) class supports which of the following concepts?

A) interfaces

B) modulary

C) information hiding

D) code reuse

E) correctness

Q3) Using the reserved word, super, one can

A) access a parent class'constructor(s)

B) access a parent class'methods and instance data

C) access a child class'constructor(s)

D) access a child class'methods and instance data

E) none of the above

Q4) Y is a derived class of Z.

A)True

B)False

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/30669

Sample Questions

Q1) A JSlider provides a list of String choices that the user can select between.

A)True

B)False

Q2) The showDialog method is part of which class?

A) JOptionPane

B) JColorChooser

C) JTextArea

D) Keyboard

E) all of the above

Q3) Which of the following classes would you use to open a GUI dialog box, which is then used to select a file to open?

A) JOptionPane

B) JTextArea

C) showOpenDialog

D) JFileChooser

E) JFileReader

Q4) Write a set of code that will allow a user to select a file through a JFileChooser and store all items in the String array list to the selected file, closing the file when done.

Q5) Why would you not need to implement a ChangeListener for the JSlider?

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/30670

Sample Questions

Q1) Write code that will create a BufferedReader object to input from standard input (System.in) an int, a double and a char.

Q2) Assume infile is a BufferedReader for a textfile and that the textfile is empty. What is returned from the message infile.readLine( ); ?

A) 0

B) null

C) a special character known as the End-of-file marker (EOF)

D) none of the above, the message causes a NullPointerException to be thrown E) none of the above, the message causes a EndOfFileException to be thrown

Q3) If an exception arises in a catch statement, and the exception is of the type caught by the catch statement, then the catch statement catches the same exception. For instance, if the following catch statement first catches an ArithmeticException and, while executing, throws another ArithmeticException, it is able to catch the second ArithmeticException as well the first. catch (ArithmeticException ex) {...}

A)True

B)False

Q4) Why might you want to create your own exception class? What purpose would it serve?

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

Chapter 12: Recursion

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) What is the result of bar(a, 8);?

A) 0

B) 5

C) 6

D) 12

E) 34

Q2) Provide a definition for the terms as they relate to programming: recursion, indirect recursion and infinite recursion.

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

Q4) Assume at some point in processing, grid's row 0 has become 3 3 3 1 1 1 0 0. Which direction will next be tried?

A) up

B) down

C) left

D) right

E) none, the recursion ends at this point

Q5) Explain what a "base case" is in a recursive method.

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/30672

Sample Questions

Q1) Assume Node temp is currently set equal to head. Which of the following while loops could be used to iterate through each element of a linked list?

A) while (head != null) head = temp.next;

B) while (temp != null) temp = temp.next;

C) while (head != null) temp = temp.next;

D) while (head != null) head = head.next;

E) while (temp != null) head = head.next;

Q2) In order to gain a last-in first-out access to data, which type of structure should be used?

A) Vector

B) Array

C) Linked List

D) Queue

E) Stack

Q3) Which of the following instructions would create an initially empty linked list?

A) Node head = new Node( );

B) Node head = Node;

C) Node head = null;

D) Node head = new Node(0);

E) Node head = list;

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.