Java Programming Solved Exam Questions - 820 Verified Questions

Page 1


Java Programming Solved

Exam Questions

Course Introduction

Java Programming introduces students to the fundamental concepts and techniques of object-oriented programming using the Java language. This course covers the basics of Java syntax, control structures, data types, classes, objects, inheritance, interfaces, exception handling, and file input/output. Through practical exercises and projects, students develop problem-solving skills and gain experience building robust and scalable applications. The course also explores the use of Java APIs and introduces best practices for code organization, documentation, and debugging in Java development environments.

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) The word "Public" is a reserved word.

A)True

B)False

Answer: False

Q2) The main method for a Java program is defined by

A) public static main( )

B) public static main(String[ ] args);

C) public static main(String[ ] args)

D) private static main(String[ ] args)

E) the main method could be defined as in A, C or D but not B

Answer: C

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

A)True

B)False

Answer: True

Q4) Java is an object-oriented programming language.

A)True

B)False Answer: True

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

Sample Questions

Q1) Which of the following would return the last character of the String x?

A) x.charAt(0);

B) x.charAt(last);

C) x.charAt(length(x));

D) x.charAt(x.length( )-1);

E) x.charAt(x.length( ));

Answer: D

Q2) Write a set of instructions to prompt the user for an int value and input it using the Scanner class into the variable x and prompt the user for a float value and input it using the Scanner class into the variable y.

Answer: Scanner scan = Scanner.create(System.in); System.out.println("Enter an integer"); int x = scan.nextInt( ); System.out.println("Enter a float"); float y = scan.nextFloat( );

Q3) In Java, 'a' and 'A' are considered to be different values.

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

Sample Questions

Q1) Only difficult programming problems require a pseudocode solution before the programmer creates the implementation (program) itself.

A)True

B)False

Answer: False

Q2) For the program to get a name interactively a Scanner object must be instantiated.

Write the Java statement to do this.

Answer: Scanner scan = new Scanner(System.in);

Q3) Consider the following two lines of code. What can you say about s1 and s2?

String s1 = "testing" + "123";

String s2 = new String("testing 123");

A) s1 and s2 are both references to the same String object

B) the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error

C) s1 and s2 are both references to different String objects

D) s1 and s2 will compare "equal"

E) none of the above

Answer: C

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

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) Regarding the software failure described at the Denver International Airport, it is critical to factor in errors and inefficiencies that always occur in a complex system.

A)True

B)False

Q2) Instance data for a Java class

A) are limited to primitive types (e.g., int, float, char)

B) are limited to Strings

C) are limited to objects(e.g., Strings, classes defined by other programmers)

D) may be primitive types or objects, but objects must be defined to be private E) may be primitive types or objects

Q3) Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal?

A) doublefoo(0);

B) doublefoo(0.555);

C) doublefoo(0.1 + 0.2);

D) doublefoo(0.1, 0.2);

E) all of the above are legal except for D

Q4) Write the constructor for this class.

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

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) The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as

A) boolean execution

B) conditional statements

C) try and catch

D) sequentiality

E) flow of control

Q2) If x is currently 0, a = 5 and b = 5, what will x become after the above statement is executed?

A) 0

B) 2

C) 3

D) 4

E) 5

Q3) In Java, selection statements consist of the if and if-else statements.

A)True

B)False

Q4) Explain what is meant by short circuiting and provide an example of short circuiting a condition with && and provide an example of short circuiting a condition with | |.

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) If x is currently equal to 3, what will the value of x be after the switch statement executes?

A) 5

B) 6

C) 11

D) 10

E) 12

Q2) Show the output that would occur from the following code, including proper spacing. for (j = 0; j < 5; j++)

{ for (k = 0; k < 5; k++) if (j!=k)

System.out.print(' '); else

System.out.print('*');

System.out.println( ); }

Q3) Rewrite the following if-else statement using a conditional operator. if (x > y) z = x; else z = y;

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) Of the various phases in software development, which of the following is usually the lengthiest?

A) specification

B) design

C) implementation

D) testing

E) maintenance

Q2) Defining formal parameters requires including each parameters type.

A)True

B)False

Q3) The idea that an object can exist separate from the executing program that creates it is called

A) transience

B) static

C) persistence

D) serialization

E) finality

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

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) Mouse Events deal with detecting the actions of the buttons on a mouse, among other things, while Mouse Motion Events deal with the movement of the mouse with/without buttons being depressed.

A)True

B)False

Q2) Given the following declarations, which of the following variables are arrays?

Int[ ] a, b;

Int c, d[ ];

A) a

B) a and b

C) a and d

D) a, b and d

E) a, b, c and d

Q3) A Polygon object in Java can be

A) built up by using a sequence of addPoint method calls

B) defined by an array of x-y coordinates

C) defined by a polyline

D) A, B, and C all are True

E) only A and B are True

Q4) Write code fragment to swap the two Strings stored by variables a and b.

Page 10

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) Java doesn't support multiple inheritance; but it does support the implementation of multiple Interfaces.

A)True

B)False

Q2) Assume the class Student implements the Speaker interface from the textbook. Recall that this interface includes two abstract methods, speak( ) and announce(String str). A Student contains one instance data, String classRank. Write the Student class so that it implements Speaker as follows. The speak method will output "I am a newbie here" if the Student is a "Freshman", "I hate school" if the Student is either a "Sophomore" or a "Junior", or "I can not wait to graduate" if the student is a "Senior". The announce method will output "I am a Student, here is what I have to say" followed by the String parameter on a separate line. Finally, the classRank is initialized in the constructor. Only implement the constructor and the methods to implement the Speaker interface.

Q3) Clicking the mouse button generates three mouse events, mousePressed, mouseClicked, and mouseReleased.

A)True

B)False

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

Sample Questions

Q1) The showDialog method is part of which class?

A) JOptionPane

B) JColorChooser

C) JTextArea

D) Keyboard

E) all of the above

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

Q3) Which statement is completely True?

A) Java upcasts automatically, but you must explicitly downcast

B) Java downcasts automatically, but you must explicitly upcast

C) Java expects the user to explicitly upcast and downcast

D) Java will both upcast and downcast automatically

E) The rules for upcasting and downcasting depend upon whether classes are declared public, protected, or private

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 with a try statement and proper catch statements to attempt to take the square root of an int value input using the BufferedReader keyboard. Catch all Exceptions that could possibly be thrown.

Q2) Character streams manage

A) byte-sized data

B) binary data

C) Unicode characters

D) ASCII characters

E) compressed data

Q3) Which statement is True about BufferedWriters

A) BufferedWriters are used because they improve runtime efficiency

B) BufferedWriters are used because they improve compile time efficiency

C) BufferedWriters can be used with input streams as well as with output streams

D) using a BufferedWriter obviates the necessity for catching IOExceptions

E) none of the above

Q4) While the Exception class is part of java.lang, IOException is part of java.io.

A)True

B)False

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

Q6) What are the three standard I/O streams and what purposes do they fulfill?

Page 13

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

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) It always is possible to replace a recursion by an iteration and vice versa.

A)True

B)False

Q2) The solution to the Towers of Hanoi has a(n) ________ complexity.

A) linear

B) polynomial

C) logarithmic

D) exponential

E) bad

Q3) What is the result of calling bar(a, 0);?

A) 0

B) 5

C) 6

D) 12

E) 34

Q4) Write a recursive method called numSegments(int order) that yields the number of line segments in a Koch snowflake of order "order."

Q5) For the Towers of Hanoi problem, show how many moves it will take to solve the problem with 5 disks, 6 disks, 7 disks, 8 disks, 9 disks, and 10 disks.

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) What value is returned by the last dequeue operation (denoted above with a d3 in comments)?

A) 3

B) 5

C) 9

D) 2

E) 4

Q2) A dynamic data structure

A) almost always is implemented using lists of one sort or another

B) is just a collection

C) almost always is implemented using references (pointers) to objects

D) can have a fixed size

E) none of the above

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

Q4) Draw this structure.

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