Skip to main content

Introduction to Programming Review Questions - 820 Verified Questions

Page 1


Introduction to Programming Review Questions

Course Introduction

Introduction to Programming is a foundational course designed to equip students with essential problem-solving skills and a solid understanding of fundamental programming concepts. Through hands-on exercises and projects, students will learn to write, test, and debug simple computer programs using a high-level programming language. The course covers key topics such as variables, data types, control structures, functions, and basic algorithms. By the end of the course, students will be able to develop clear, efficient, and well-structured code, laying the groundwork for further studies in computer science and related fields.

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

Page 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) A color image is broken down into individual pixels (points), each of which is represented by

A) a 1 for white and a 0 for black

B) 3 values denoting the intensity of red, green, and blue in the image

C) a single number indicating the intensity of color between white and black

D) two numbers, a value that denotes where between white and black the color is, and a brightness

E) none of the above, it is not possible to represent a color image

Answer: B

Q2) Which of the following characters does not need to have an associated "closing" character in a Java program?

A) {

B) (

C) [

D) <

E) all of these require closing characters

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 of the following is True regarding the mod operator, %?

A) It can only be performed on int values and its result is a double

B) It can only be performed on int values and its result is an int

C) It can only be performed on float or double values and its result is an int

D) It can only be performed on float or double values and its result is a double E) It can be performed on any numeric values, and the result always is numeric

Answer: E

Q2) Given two points in an applet represented by the four int variables x1, y1, x2 and y2, write a paint method to draw a line between the two points and write the location of the two points next to the two points. Answer: public void paint(Graphics page)

{ page.setColor(Color.blue); page.drawLine(x1, y1, x2, y2); page.drawString("" + x1 + ", " + y1, x1, y1); page.drawString("" + x2 + ", " + y2, x2, y2); }

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

Sample Questions

Q1) What is the advantage of putting an image in a JLabel instance?

A) It becomes part of the component and is laid out automatically

B) It becomes part of the container and is automatically scaled

C) Although it becomes part of the instance, it still must be drawn separately

D) The runtime efficiency is greatly improved

E) None of the above

Answer: A

Q2) What is the purpose of the ImageIcon class?

Answer: The ImageIcon class is used to represent an image that is included in a label. The ImageIcon constructor takes the name of an image file (which may contain a JPEG, GIF, or PNG image) and loads it into the object.

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

Q4) Write a statement using a Scanner method to get the first name interactively. Answer: firstName = scan.nextLine( );

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) A constructor may contain a return statement so long as no value (or expression) is returned.

A)True B)False

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

Q3) Assume that another method has been defined that will compute and return the student's class rank (Freshman, Sophomore, etc). It is defined as: public String getClassRank( )

Given that s1 is a student, which of the following would properly be used to get s1's class rank?

A) s1 = getClassRank( );

B) s1.toString( );

C) s1.getHours( );

D) s1.getClassRank( );

E) getClassRank(s1);

Q4) Write a statement to output the volume of the blue box.

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

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) What is wrong, logically, with the following code? If (x > 10) System.out.println("Large");

Else if (x > 6 && x <= 10) System.out.println("Medium");

Else if (x > 3 && x <= 6) System.out.println("Small"); Else System.out.println("Very small");

A) There is no logical error, but there is no need to have (x <= 10) in the second conditional or (x <= 6) in the third conditional

B) There is no logical error, but there is no need to have (x > 6) in the second conditional or (x > 3) in the third conditional

C) The logical error is that no matter what value x is, "Very small" is always printed out D) The logical error is that no matter what value x is, "Large" is always printed out E) There is nothing wrong with the logic at all

Q2) String s1 is said to overlap String s2 if all of the characters in s1 also appear in s2. Write a set of code that will set the boolean variable overlap to True if s1 overlaps s2 and false otherwise. Assume both s1 and s2 have already been input.

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 do loop differs from the while loop in that A) the while loop will always execute the body of the loop at least once B) the do loop will always execute the body of the loop at least once C) the do loop will continue to loop while condition in the while statement is false and the while loop will continue to loop while the condition in the while statement is True D) the while loop will continue to loop while condition in the while statement is false and the do loop will continue to loop while the condition in the while statement is True E) none of the above, there is absolutely no difference between the two types of loops

Q2) This paint method will draw several bars (sort of like a bar graph). How many bars will be displayed?

A) 4

B) 5

C) 6

D) 10

E) 20

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

Sample Questions

Q1) If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if C1 c = new C1( ); is performed at one point of the program, then a later instruction c.whichIsIt( ); will invoke the whichIsIt method defined in C1.

A)True

B)False

Q2) To implement Comparable for the ChessPiece class, the current ChessPiece's type is compared to a ChessPiece passed as a parameter. The method should return 0 if the types are equal, -1 if this piece's type is a lesser piece than the parameter's type, and 1 if this piece's type is a greater piece than the parameter's type. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King." Write the proper method to implement Comparable for this class.

Q3) Assume a class Foo implements Comparable. Without knowing anything else about the Foo class, write an equal method that returns True if the Foo parameter passed to this Foo is equal to this Foo as determined by using the implementation of Comparable.

Q4) Provide a reason why a method would be declared static.

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

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) Write a method to compute and return the value of max - min where max is the largest element of an int array and min is the smallest element of an int array. The method is passed the int array and an int value that denotes the number of elements in the array. You may assume that the int array has at least 1 element in it.

Q2) Which of the following lists of numbers would accurately show the array after the first pass through the Selection Sort algorithm?

A) 9, 4, 12, 2, 6, 8, 18

B) 4, 9, 12, 2, 6, 8, 18

C) 2, 4, 12, 9, 6, 8, 18

D) 2, 4, 6, 8, 9, 12, 18

E) 2, 4, 9, 12, 6, 8, 18

Q3) The Key Events include

A) keyPressed, keyReleased

B) keyPressed, keyReleased, keyTyped

C) keyPressed, keyReleased, keyTyped, keyDown, keyUp

D) keyDown, keyUp, keyTyped

E) none of the above

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

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) Although classes can be inherited from one-another, even Abstract classes, interfaces cannot be inherited.

A)True

B)False

Q2) Assume a class Triangle has been defined. It has three instance data, Point p1, p2, p3. The class also has a constructor that receives the 3 Points and initializes p1, p2, and p3, a toString method that outputs the 3 Points, and a computeSurfaceArea method that calculates the surface area of the Triangle (as an int value). We want to extend this class to represent a 3-dimensional Pyramid, which consists of 4 Points. Since the Pyramid will consist of in essence, 4 triangles, computeSurfaceArea for the Pyramid will compute 4 * the surface area of the Triangle made up of 3 of those 4 Points. Write the Pyramid class to handle the difference(s) between a Pyramid and the previously defined Triangle. Assume the instance data of Triangle are protected and all methods are public. Also assume that the class Point has a toString method.

Q3) The protected visibility modifier provides the best possible encapsulation that permits inheritance.

A)True

B)False

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

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) Which of the following is a listener class for a JSlider?

A) ListListener

B) ActionListener

C) ButtonListener

D) ChangeListener

E) SlideListener

Q2) Write a set of code that will create 4 JButtons and add each of these to a JPanel so that they appear in a 2x2 grid. The JButtons will not have any text appear in them (i.e. no commands or names) but instead, will each appear as a color set by the user by using JColorChooser.

Q3) What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0.

For (j=0; j < list.length; j++)

If (list[j] < temp) c++;

A) It finds the smallest value and stores it in temp

B) It finds the largest value and stores it in temp

C) It counts the number of elements equal to the smallest value in list

D) It counts the number of elements in list that are less than temp

E) It sorts the values in list to be in ascending order

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) A finally clause will execute

A) only if the try statement that precedes it does not throw an exception

B) only if the try statement that precedes it throws an exception that is caught C) only if the try statement that precedes it throws an exception that is not caught D) only if the try statement that precedes it throws an exception, whether it is caught or not

E) in any circumstance

Q2) The following defines a new Exception called AnewException. public Exception ANewException { public ANewException(String message) { super(message); } } A)True B)False

Q3) Write a save method that will save a given student to the String filename passed as a parameter.

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

Sample Questions

Q1) Consider the following recursive sum method: public int sum(int x)

{ if (x = = 0) return 0; else return sum(x - 1) + 1;

}

If the base case is replaced with "if (x = = 1) return 1;" the method will still compute the same thing.

A)True

B)False

Q2) Aside from writing recursive methods, another way that recursion is often used is to define

A) words in English

B) mathematical functions

C) rules and laws

D) child classes of a parent class in object-oriented programming

E) recursion is used in all of the above

Q3) It always is possible to replace a recursion by an iteration and vice versa.

A)True

B)False

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) A variation of a linked list is a circular linked list where the last Node in the list has next = head rather than next = null. One problem with this type of list is that

A) it wastes memory space since head already points at the first Node, so the last one does not need to

B) there is no ability to add a new Node at the end of the list since the last Node points at the first Node

C) it is more difficult to traverse the list since the old terminating condition, (next = = null), is no longer True for the last node

D) a header Node for this type of list is more complex

E) all of the above

Q2) This type of linked list is referred to as a

A) singly linked list

B) doubly linked list

C) singly linked list with a header node

D) doubly linked list with a header node

E) singly linked list with a head and rear references

Q3) A Stack s stores int values. Show what s will look like after each of the following instructions is executed.

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
Introduction to Programming Review Questions - 820 Verified Questions by Quizplus - Issuu