Skip to main content

Introduction to Programming Mock Exam - 639 Verified Questions

Page 1


Introduction to Programming

Mock Exam

Course Introduction

Introduction to Programming is designed to give students a comprehensive foundation in computer programming concepts and problem-solving strategies using a high-level programming language. The course introduces basic principles such as variables, data types, conditional statements, loops, functions, and arrays, while emphasizing logical thinking and program structure. Students will gain hands-on experience by writing, testing, and debugging their own code, preparing them to tackle more advanced programming courses and real-world computing challenges. No prior programming experience is required, making this course ideal for beginners seeking to develop a solid understanding of programming fundamentals.

Recommended Textbook

Java Foundations 3rd Edition by John Lewis

Available Study Resources on Quizplus

16 Chapters

639 Verified Questions

639 Flashcards

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

Page 2

Chapter 1: Introduction

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Explain the difference between a compile-time error and a run-time error. Give an example of each.

Answer: A compile-time error will cause the compiler to exit with an error, and therefore the program will not be properly translated. A program with a run-time error will compile and be translated, but will crash or throw an exception while it is running. An example of a compile-time error is forgetting a semicolon. An example of a run-time error is dividing by zero.

Q2) The _____________ of an object define it define its potential behaviors.

A) attributes

B) white spaces

C) variables

D) methods

E) name

Answer: D

Q3) Comments affect the run-time execution of a program.

A)True

B)False

Answer: False

Q4) Write an application that prints the first few lines of a song (your choice).

Answer: 11edd9cc_5a45_7376_84e8_afca069acf96_TB2841_00

Page 3

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

Chapter 2: Data and Expressions

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Write a short application that converts inches to centimeters. It should read the number of inches from the user as a floating point number and output the number of inches and the number of centimeters at the end of the program. Note that there are 2.54 centimeters in an inch.

Answer: 11edd9d0_01b8_da9d_84e8_4dcb8b77e1bb_TB2841_00

Q2) Explain the difference between the print and the println methods.

Answer: The println method performs a carriage return after printing the specified characters. This means the next output will begin on the next line. The print method does not do this, and therefore the next output will begin right after the previous output.

Q3) Which of the following is an example of an invalid expression in Java?

A) result = a + b;

B) result = (14 + 9) * 5;

C) result = ((19 + 4) - 5;

D) result = firstNum % secondNum;

E) result = firstNum / secondNum % thirdNum;

Answer: C

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

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Assume that we have a Random object referenced by a variable called generator. Which of the following lines will generate a random number in the range 5-20 and store it in the int variable randNum?

A) randNum = generator.nextInt(15) + 5;

B) randNum = generator.nextInt(15) + 6;

C) randNum = generator.nextInt(16) + 5;

D) randNum = generator.nextInt(16) + 6;

E) none of the above

Answer: C

Q2) Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?

A) String prefix = listing.front(5);

B) String prefix = listing.front(6);

C) String prefix = listing.substring(1,5);

D) String prefix = listing.substring(0,5);

E) String prefix = listing.firstChars(5);

Answer: D

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

Chapter 4: Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Which of the following is not a valid relational operator in Java

A) <=

B) >

C) ==

D) <>

E) !=

Q2) It is possible to implement a switch statement using if statements.

A)True

B)False

Q3) Using a while loop, write a code fragment that computes the sum of the first n natural numbers (i.e. 1, 2, 3, 4, ... n), where n is an integer variable already defined in the program.

Q4) Write a snippet of code that determines which of two integer variables, intOne and intTwo, contains a larger number, and print out the larger one. If they are equal, the output should say that.

Q5) In Java, a boolean expression is limited to having exactly 2 logical operators.

A)True

B)False

Q6) Write a for loop to print the even numbers from 1 to 100 (inclusive).

Page 6

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

Chapter 5: Writing Classes

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) A(n) ___________________ object is one that is made up, at least in part, of other objects.

A) static

B) aggregate

C) encapsulated

D) private

E) public

Q2) Explain why a static method cannot refer to an instance variable.

Q3) Write a method called countSpaces that takes in a String as a parameter and returns an integer that represents the number of space characters (' ') contained in the string, false otherwise..

Q4) Aggregation is sometimes described as a has-a relationship.

A)True

B)False

Q5) The ________________ reference always refers to the currently executing object.

A) null

B) static

C) final

D) actual

E) this

Page 7

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

Chapter 6: Graphical User Interfaces

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) A container is goverened by a(n) __________________, which determines exactly how the components added to the panel will be displayed.

A) event

B) content pane

C) JFrame object

D) JPanel object

E) layout manager

Q2) Which of the following is a fundamental idea of good GUI design?

A) Know the user

B) Prevent user errors

C) Optimize user abilities.

D) Be consistent.

E) all of the above

Q3) GUI is an acronym for _______________________.

A) graphical UML interface

B) graphical UML implementation

C) graphical user implementation

D) graphical user interface

E) none of the above

Q4) Give an example of a common use of a dialog box.

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

Chapter 7: Arrays

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Which of the following array declarations are invalid?

A) int[] grades = new int[5];

B) int grades[] = new int[5];

C) int[] grades = { 91, 83, 42, 100, 77 };

D) all of the above are valid

E) none of the above are valid

Q2) Write a method called average that accepts an array of floating point numbers and returns their average.

Q3) What is the precedence of the index operator ( [ ] ) relative to other operators in Java?

A) It has the lowest precedence of all Java operators.

B) It has a higher precedence than addition, but a lower precedence than multiplication.

C) It has a higher precedence than multiplication, but a lower precedence than addition.

D) It has the highest precedence of all Java operators.

E) [ ] is not an operator.

Q4) The foreach loop can be used to process each element of an array.

A)True

B)False

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

Chapter 8: Inheritance

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) What does it mean for a class to be declared as final? What does it mean for a method to be declared as final?

Q2) Draw a hierarchy of Animals. The hierarchy should include the following entities: Animal, Reptile, Mammal, Bear, Human, Iguana, and Dolphin.

Q3) In Java subclass can only extend one parent class.

A)True

B)False

Q4) When a variable is declared in a subclass has the same name as a variable declared in a superclass, it is called a _______________ variable. A) final B) shadow

C) static

D) dead

E) this is not allowed in Java

Q5) Compare and contrast the private visibility modifier to the protected visibility modifier. Why is the protected visibility modifier a better choice in an inheritance hierarchy?

Q6) Explain the relevance of the Object class to the Java programming language.

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

Chapter 9: Polymorphism

Available Study Resources on Quizplus for this Chatper

39 Verified Questions

39 Flashcards

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

Sample Questions

Q1) In Java, polymorphic method binding occurs ____________________ .

A) at run time

B) at compile time

C) never

D) when a programmer writes the code

E) during the testing phase of software development

Q2) Can references to interface types be polymorphic? Explain.

Q3) The compareTo method of the Comparable interface returns a boolean value.

A)True

B)False

Q4) Why can't an interface be instantiated?

Q5) Describe the Iterator interface.

Q6) Describe the compareTo method the circumstances under which it returns different values.

Q7) How do interfaces relate to multiple inheritance?

Q8) A parameter to a method can be polymorphic. A)True B)False

11

Q9) Are there any differences between extending a class and implementing an interface?

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

Chapter 11: Recursion

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) A program with infinite recursion will act similarly to a program with an infinite loop.

A)True

B)False

Q2) __________________ recursion results from the lack of a base case.

A) Indirect

B) Direct

C) Infinite

D) Spiral

E) none of the above

Q3) The Fibonacci sequence is defined as the sum of the two previous elements of the sequence, with the first and second numbers in the sequence being 0 and 1 respectively. Write a recursive method that computes the nth Fibonacci number.

Q4) What is recursion?

Q5) Write a recursive method that computes the sum of the first n integers.

Q6) Describe a recursive solution to determine whether a String object is a palindrome. You may assume that the string only contains lower case characters (i.e. no numbers, spaces, punctuation, etc). Hint: It may be easiest to describe your solution using pseudocode.

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

Chapter 10: Exceptions

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Which of the following exceptions are unchecked?

A) RuntimeException

B) IllegalAccessException

C) NoSuchMethodException

D) ClassNotFoundException

E) none of the above

Q2) Consider the following code fragment.

String s; for(int i = 0; i < s.length(); i++)

System.out.println(s.charAt(i));

What exception will be thrown by this code and why?

Q3) The Exception class is a subclass of the Object class.

A)True

B)False

Q4) A finally clause is always required in a try-catch block.

A)True

B)False

Q5) Is an exception an object? Explain.

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

Chapter 12: Searching and Sorting

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Which of the following is not a sorting algorithm?

A) Bubble sort

B) Quick sort

C) Merge sort

D) Selection sort

E) all of the above are sorting algorithms

Q2) What is the complexity of the following code (in terms of the length of the array)? for(int i = 0; i < 5; i++) System.out.println(array[i]);

Q3) ____________________ is the process of arranging a group of items into a defined order.

A) Searching

B) Sorting

C) Selecting

D) Helping

E) none of the above

Q4) Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. The method should use a linear search.

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

Chapter 13: Trees

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) What is an internal node in a tree?

Q2) In an inorder traversal, the elements of a tree are visited in order of their distance from the root.

A)True

B)False

Q3) Explain the implementation of an postorder traversal.

Q4) Explain the implementation of a level-order traversal of a tree.

Q5) One method of implementing a tree using an array involves storing the child of the element at the index n in the array at indexes

A) n+1 and n+2

B) 2<sup>n</sup> and 2<sup>2n</sup>

C) 2n+1 and 2n+2

D) n-1 and n-2

E) none of the above will work

Q6) A binary tree is a tree in which any node can have at most two children.

A)True

B)False

Q7) If a tree has order 4, what does this mean?

Q8) What does it mean for a tree to be balanced?

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

Chapter 14: Introduction to Collections and Stacks

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) A postfix expression can be easily evaluated using a queue.

A)True

B)False

Q2) A stack is a ___________________ data structure.

A) LIFO

B) FIFO

C) link based

D) array based

E) none of the above

Q3) List the five basic operations on a queue.

Q4) A queue is the ideal collection to use when ____________________ .

A) implementing a radix sort

B) evaluating a postfix expression

C) evaluating an infix expression

D) implementing a quick sort

E) none of the above

Q5) What is wrong with implementing a queue via an array where index 0 represents the front of the queue?

Q6) List the five basic operations on a stack.

Q7) What is wrong with the java.util.Stack implementation of a stack?

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

Chapter 15: Heaps and Priority Queues

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Which of the following is always true when adding an element to a heap?

A) The new element will always be a leaf.

B) The new element will always be the root.

C) The new element will always be an internal node.

D) The new element will always have 2 children.

E) none of the above is always true

Q2) What is a binary search tree?

Q3) Suppose we have a class called BinaryTree that includes a find method. If we extend the class to create a BinarySearchTree class, should we override the find method or use it as is? Explain.

Q4) A _____________________ is a tree whose elements are organized to facilitate finding a particular element when needed.

A) full tree

B) complete tree

C) binary tree

D) search tree

E) none of the above

Q5) Explain the process of removing an element from a binary search tree.

Q6) Explain how an element is added to a heap.

Q7) What is a heap?

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

Chapter 16: Graphs

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

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

Sample Questions

Q1) Consider the following undirected graph. vertices: 1, 2, 3, 4, 5 edges: (1,2),(3,4), (2,4), (2, 3) Is the graph acyclic?

Q2) What data structure is used to support a depth-first traversal of a graph?

Q3) A(n) _______________________ is one implementation of a graph where the graph is implemented as a linked structure, and each node contains a structure that contains links to all other nodes.

A) adjacency list

B) adjacency matrix

C) digraph list

D) graph node

E) none of the above

Q4) A spanning tree of a graph is a tree with that always has which of the following properties?

A) It includes some of the edges and some of the vertices of the graph.

B) It includes all of the edges and some of the vertices of the graph.

C) It includes some of the edges and all of the vertices of the graph.

D) It includes all of the edges and all of the vertices of the graph.

E) none of the above

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

Turn static files into dynamic content formats.

Create a flipbook
Introduction to Programming Mock Exam - 639 Verified Questions by Quizplus - Issuu