

Introduction to Programming
Pre-Test Questions

Course Introduction
Introduction to Programming is designed to provide students with a foundational understanding of computer programming concepts and techniques. The course introduces basic programming constructs such as variables, data types, control structures (conditionals and loops), functions, and input/output operations using a beginner-friendly programming language. Emphasis is placed on problem-solving skills, algorithmic thinking, and writing clear, efficient, and well-documented code. Students will engage in practical programming exercises and projects that reinforce theoretical knowledge and develop computational logic essential for future computer science courses.
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 document of text is 15 pages long. Each page contains approximately 200 words and the average length of each word is 5 characters. Also assume one blank space between each word and no punctuation. How many bytes will it take to store this document in memory or on disk using ASCII?
Answer: A character is stored in ASCII using 8 bits or 1 byte. Therefore, 5 characters per word plus 1 blank space between words take 6 bytes per word (except for the first). Each page stores 200 words and there are 15 pages. So we need 15 * 200 * 6 - 1 (no blank space to start the text) = 17,999 bytes which is 17.58 kilobytes, or nearly 18 Kbytes.
Q2) Java is an example of a(n)
A) machine language
B) assembly language
C) high-level language
D) fourth generation language
E) both C and D
Answer: E
Q3) Inheritance is a form of software reuse.
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/31386
Sample Questions
Q1) How many lines of output are provided by this program?
A) 1
B) 2
C) 3
D) 4
E) 5
Answer: B
Q2) 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
Q3) In order to generate a random number, you must use Math.random( ).
A)True
B)False
Answer: False
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) Why does one set up a containment hierarchy?
Answer: It is common to use multiple layers of nested panels to organize and group components in various waysthis is called a containment hierarchy. It allows you to create sophisticated layouts that scale (or do not scale) appropriately.
Q2) Which of the following GUI components is used to accept input into a JFrame?
A) JLabel
B) JPanel
C) JInput
D) JTextField
E) JInputField
Answer: D
Q3) 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);
Q4) Write a statement using a Scanner method to get the first name interactively. Answer: firstName = scan.nextLine( );
Q5) Write a method to extract the initial from the first name. Answer: firstInitial = firstName.substring(0,1);
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) Write a toString method that returns the player's name, position and batting average formatted to have 1 digit to the left of the decimal and 3 digits to the right of the decimal. Assume DecimalFormat has been imported.
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) The following method header definition will result in a syntax error: public void aMethod( );
A)True
B)False
Q4) Write the constructor for this class.
Q5) 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?
Q6) Write the statement to instantiate an Box object, blueBox, with a length of 6, width of 4, and height of 2.
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) 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 | |.
Q2) An if statement may or may not have an else clause, but an else clause must be part of an if statement.
A)True
B)False
Q3) If x is an int where x = 0, what will x be after the following loop terminates? While (x < 100)
X *= 2;
A) 2
B) 64
C) 100
D) 128
E) none of the above, this is an infinite loop
Q4) In Java, selection statements consist of the if and if-else statements.
A)True
B)False
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/31390
Sample Questions
Q1) If a switch statement is written that contains no break statements whatsoever,
A) this is a syntax error and an appropriate error message will be generated
B) each of the case clauses will be executed every time the switch statement is encountered
C) this is equivalent to having the switch statement always take the default clause, if one is present
D) this is not an error, but nothing within the switch statement ever will be executed
E) none of the above
Q2) 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
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) Draw the JFrame as you think it would appear given the following set of code:
JButton jb1 = new JButton("A");
JButton jb2 = new JButton("B"); JButton jb3 = new JButton("C"); JButton jb4 = new JButton("D"); JButton jb5 = new JButton("E"); JButton jb6 = new JButton("F");
JButton jb7 = new JButton("G");
JPanel jp1 = new JPanel(new GridLayout(3, 3));
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jb4);
jp1.add(jb5);
jp1.add(jb6); jp1.add(jb7);
JFrame jf = new JFrame( ); jf.getContentPane( ).add(jp1); jf.pack( );
jf.setVisible(True);
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) Write a method to output all elements of a two-dimensional array of int values as a table of rows and columns. Use "\t" to get elements to line up properly. The method is passed the two-dimensional array and two int values that denote the number of both dimensions (rows followed by columns).
Q2) The "off-by-one" error associated with arrays arises because
A) the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far
B) the last array index is at length + 1 and loops may only iterate to length, missing one
C) the last array element ends at length - 1 and loops may go one too far
D) programmers write a loop that goes from 0 to length - 1 whereas the array actually goes from 1 to length
E) none of the above, the "off-by-one" error has nothing to do with arrays
Q3) It is possible to sort an array of int, float, double or String, but not an array of an Object class such as a CD class.
A)True
B)False
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.

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 mouse event is a(n)
A) listener
B) object
C) interface
D) GUI component
E) all of the above
Q2) The relationship between a parent class and a child class is referred to as a(n) ________ relationship.
A) has-a B) is-a C) was-a D) instance-of E) alias
Q3) Y is a derived class of Z.
A)True
B)False
Q4) What instance data and methods might you define for SportsCar that are not part of Car?
Q5) Explain the difference between using an imported class and extending a class.
Q6) What methods inherited from Car should SportsCar override?
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) 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
Q2) Consider this statement: If you declare a (polymorphic) reference variable, v, to be of type Object, by saying: Object v; then v can refer to any kind of object without restriction. If "object" means an instance of the Object class, is this statement True?
Why or why not?
If "object" means any kind of Java data, is this statement True?
Why or why not?
Q3) 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 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) What are the three standard I/O streams and what purposes do they fulfill?
Q2) Write a set of code that will allow a user to select a file through a JFileChooser, read each item of the file, outputting each item to the screen, and close the file at the end.
Q3) Write a save method that will save a given student to the String filename passed as a parameter.
Q4) A combo box allows the user to select one of several options from a "drop down" menu.
A)True
B)False
Q5) 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
Q6) 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.
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) Rewrite the following iterative method as a recursive method that computes the same thing. NOTE: your recursive method will require an extra parameter. public String reversal(String x) { int y = x.length( ); String s = ""; for (int j = y-1; j >=0; j--) s += x.charAt(j); return s; }
Q2) What condition defines the base case for this method?
A) (x > 1)
B) (x = = 1)
C) (x = = 0)
D) (x <= 0)
E) (x <= 1)
Q3) The Koch snowflake has an infinitely long perimeter, but it contains a finite area. 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) The push and enqueue operations are essentially the same operations, push is used for Stacks and enqueue is used for Queues.
A)True
B)False
Q2) Two abstract data types are the ordered list and the unordered list. Explain how these two ADTs are similar and how they will differ. To answer this question, assume that you do not know how they are implemented (that is, whether they are implemented using an array or a linked list).
Q3) An abstract data type not covered in detail in the chapter is the Set ADT. A Set is like a set as covered in your Mathematics courses. For instance, a set of even numbers might be {2, 4, 8, 12, 18, 32}. List 6 operations that you might implement for a Set ADT.
Q4) Trees and graphs, because they are dynamic in nature, cannot be implemented using Java arrays.
A)True
B)False
Q5) What changes would have to be made to the BookList class in order to properly use the separate BookNode class?
Q6) Draw this structure.
To view all questions and flashcards with answers, click on the resource link above. Page 15