Computer Science I Solved Exam Questions - 758 Verified Questions

Page 1


Computer Science I Solved Exam Questions

Course Introduction

Computer Science I is an introductory course that provides a fundamental understanding of computer science principles and programming. Students learn the basics of algorithm development, problem-solving techniques, and programming structures such as variables, control statements, functions, and data types. Emphasis is placed on writing, testing, and debugging code, often using a high-level programming language such as Python or Java. The course also introduces students to software development best practices and the foundational concepts necessary for advanced computer science coursework.

Recommended Textbook

Absolute Java 5th Edition by Walter Savitch

Available Study Resources on Quizplus

20 Chapters

758 Verified Questions

758 Flashcards

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

Page 2

Chapter 1: Getting Started

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

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

Sample Questions

Q1) What steps must the programmer take to create an executable Java program?

Answer: First,the programmer must create the source code.The programmer creates a Java class that is contained in a file with the same name as the class.The source code file ends with the .java extension.Next,the programmer uses a tool called a compiler to translate the source code into Java byte-code.If the source code is syntactically correct,a file containing the byte-code is created.This file has the same name as the source code file with one exception,the byte-code file ends in the .class extension. Once the .class is generated,it may be executed on any computer that has the Java Virtual Machine (JVM)installed on it.

Q2) What does the String method trim()do? Give an example of its use.

Answer: The string method trim removes leading and trailing white space,as well as the tab and new-line character from String objects.For example,the following is an invocation of trim(): String s = userInput.trim(); where s represents the new String with no white space,tab or new-line characters.

Q3) Java uses the ASCII character set.

A)True

B)False

Answer: False

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

Chapter 2: Console Input and Output

Available Study Resources on Quizplus for this Chatper

29 Verified Questions

29 Flashcards

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

Sample Questions

Q1) Explain the significance of the pattern string used by the DecimalFormat object,and give an example of a valid pattern.

Answer: The pattern string represents the format in which the number passed to the DecimalFormat object is formatted.The pattern can either specify the exact number of digits before and after the decimal,or it can specify the minimum numbers of digits.The character '0' is used to represent a required digit and the character '#' is used to represent optional digits.Valid patterns include: "0.00","#0.0##".

Q2) If there is no loss of efficiency in importing an entire Java package instead of importing only classes you use into your program,why would you not just import the entire package?

Answer: Importing only the classes you need into your program makes your program easier to read as well as aiding in documenting the program.Program readability is very important since humans read computer programs,too.

Q3) Efficiency is lost in importing the entire package instead of importing the classes you use.

A)True

B)False

Answer: False

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

Chapter 3: Flow of Control

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

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

Sample Questions

Q1) An empty statement is defined as a loop that runs forever.

A)True

B)False

Answer: False

Q2) The looping mechanism that always executes at least once is the _____________ statement.

A)if else

B)do while C)while

D)for

Answer: B

Q3) What is a sentinel value and how is it used?

Answer: A sentinel value is a value that should never be encountered in the input of the program.It is used to control looping mechanisms when the number of repetitions is unknown.When the sentinel value is encountered,the loop terminates.A sentinel value is commonly used with while and do .while statements.

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

Chapter 4: Defining Classes I

Available Study Resources on Quizplus for this Chatper

44 Verified Questions

44 Flashcards

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

Sample Questions

Q1) Only the default constructor has the this parameter.

A)True

B)False

Q2) A variable whose meaning is confined to an object of a class is called:

A)instance variable

B)local variable

C)global variable

D)none of the above

Q3) A variable whose meaning is confined to a method definition is called an/a

A)instance variable

B)local variable

C)global variable

D)none of the above

Q4) Write a method called isEqual that returns a Boolean value.The method compares two integers for equality.

Q5) It is considered good programming practice to validate a value passed to a mutator method before setting the instance variable.

A)True

B)False

Q6) Define the terms arguments and parameters.How are they different?

Page 6

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

Chapter 5: Defining Classes Ii

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

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

Sample Questions

Q1) Define boxing and unboxing.

Q2) Static variables are often used:

A)in arithmetic expressions

B)to communicate between objects

C)within looping structures

D)all of the above

Q3) Create a Java class named Book with instance variables title,author,ISBN,and yearPublished.Include javadoc style comments to describe your interface.Such a class would normally have methods,but you are not required to supply any methods.

Q4) A condition that allows a programmer to circumvent the private modifier and change the private instance variable is called:

A)a copy constructor

B)a privacy leak

C)a class invariant

D)an anonymous object

Q5) You may use methods of the Math class without an import statement.

A)True

B)False

Q6) Explain in detail how main memory works.

Page 7

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

Chapter 6: Arrays

Available Study Resources on Quizplus for this Chatper

47 Verified Questions

47 Flashcards

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

Sample Questions

Q1) An arrays length instance variables value can be changed by a program. A)True B)False

Q2) What is the output of the following code? int[] numbers = new int[10]; for(int i=0; i < numbers.length; ++i) numbers[i] = i * 2; for(int i=0; i < numbers.length; ++i) System.out.print(numbers[i] / 2 + " "); System.out.println();

Q3) What are three ways you can use the square brackets [ ] with an array name?

Q4) Given the following character array char[] h = {'H','E','L','L','O'}; Write a Java statement that will create a new String object from the character array.

Q5) Discuss how you could represent a table of related records using a multidimensional array.

Q6) Write a Java method as well as any facilitator methods needed to perform a sort on an array of whole numbers in descending order.

Q7) Declare and create a 10 x 10 multidimensional array of doubles.

Page 8

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

Chapter 7: Inheritance

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

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

Sample Questions

Q1) What does a derived class automatically inherit from the base class?

A)instance variables

B)static variables

C)public methods

D)all of the above

Q2) The Object class contains the method:

A)getClass()

B)toString()

C)equals()

D)all of the above

Q3) What is an "is a" relationship? How does it apply to the world of objects?

Q4) In using the keyword this in place of super(),the invocation of this must be the ___________ action taken by the constructor.

A)first

B)last

C)it does not matter

D)none of the above

Q5) Define a base class to represent a Clock.Your class should have instance variables for hours,minutes and seconds.

Q6) What is encapsulation?

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

Chapter 8: Console Input and Output

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

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

Sample Questions

Q1) Override the clone method inherited in the Dress Shoes class created in number 10 above.

Q2) Polymorphism refers to the ability to associate many meanings to one method through dynamic binding.

A)True

B)False

Q3) Derive a class named Tennis Shoes from the base class created in number 9 above.

Q4) Describe the limitations of the copy constructor.

Q5) A class that has at least one abstract method is called an:

A)concrete class

B)encapsulated class

C)abstract class

D)private class

Q6) Downcasting should be used only in situations where it makes sense.

A)True

B)False

Q7) What are the advantages of polymorphism?

Q8) Derive a class named Dress Shoes from the base class created in number 9 above.

Q10) Explain the difference between early and late binding. Page 10

Q9) What is polymorphism and how does it relate to late binding?

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

Chapter 9: Exception Handling

Available Study Resources on Quizplus for this Chatper

45 Verified Questions

45 Flashcards

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

Sample Questions

Q1) ArrayIndexOutOfBoundsException is a descendent of the class RuntimeException.This means:

A)the exception must be caught

B)a finally block must be included

C)the exception does not have to be explicitly caught

D)none of the above

Q2) Every exception class is an ancestor of the class Exception.

A)True

B)False

Q3) The catch block has ________ parameters.

A)zero

B)one

C)two

D)three

Q4) Try blocks contain code that could possibly:

A)handle an exception

B)throw an exception

C)catch an exception

D)display an exception

Q5) What is the purpose of the method getMessage()when used with exception handling?

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

Chapter 10: File IO

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

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

Sample Questions

Q1) The preferred stream classes for processing binary files are ObjectInputStream and ObjectOutputStream.

A)True

B)False

Q2) Write a Java statement to create an input stream to a file named "statistics.dat".

Q3) In Java,when you open a text file you should account for a possible:

A)FileNotFoundException

B)FileFullException

C)FileNotReadyException

D)all of the above

Q4) Binary files store data in the same format that is used by any common text editor.

A)True

B)False

Q5) The methods of the scanner class do not behave the same when reading from a text file as they do when used to read from the keyboard.

A)True

B)False

Q6) Explain the differences between a text file,an ASCII file and a binary file.

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

Chapter 12: Uml and Patterns

Available Study Resources on Quizplus for this Chatper

22 Verified Questions

22 Flashcards

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

Sample Questions

Q1) Pseudocode is a mixture of programming language and English.

A)True

B)False

Q2) Draw a UML inheritance diagram for possible classes used to represent a bank account.

Q3) The Adaptor pattern transforms one class into a different class without changing the underlying class.

A)True

B)False

Q4) In a UML class diagram,the sharp (#)indicates:

A)public access

B)protected access

C)private access

D)package access

Q5) Draw a UML class diagram for a class that represents a savings account.

Q6) The first section of a UML class diagram specifies the:

A)class members

B)class name

C)class methods

D)class modifiers

Page 14

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

Chapter 13: Interfaces and Inner Classes

Available Study Resources on Quizplus for this Chatper

32 Verified Questions

32 Flashcards

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

Sample Questions

Q1) An interface and all of its method headings are normally declared to be:

A)public

B)private

C)protected

D)package access

Q2) An interface can contain defined constants as well as method headings or instead of method headings.

A)True

B)False

Q3) What are the obligations of a class that implements a specific interface?

Q4) When using the clone method from an inherited base class you should account for a _________ exception.

A)CloneNotFoundException

B)CloneEmptyException

C)CloneNotSupportedException

D)CloneNotEmptyException

Q5) You can not derive an interface from a base interface. A)True

B)False

Q6) What are the rules of total ordering?

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

Chapter 14: Generics and the Arraylist Class

Available Study Resources on Quizplus for this Chatper

31 Verified Questions

31 Flashcards

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

Sample Questions

Q1) Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.

A)True

B)False

Q2) When using ArrayLists the method _______ can be used to save memory:

A)trimToSize()

B)trimDown()

C)trimOff()

D)None of the above

Q3) Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 for the first time?

A)recVehicles.set(3,"boat"); B)recVehicles.set("boat",3);

C)recVehicles.add(3,"boat");

D)recVehicles.add("boat",3);

Q4) A class definition can have more than one type parameter.

A)True

B)False

Q5) What is a parameterized class?

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

Chapter 15: Linked Data Structures

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

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

Sample Questions

Q1) What is the result of a postorder traversal of the binary search tree created in question 12 above?

Q2) Recursively visiting the left subtree,right subtree and then the root describes:

A)preordering processing

B)inorder processing

C)postorder processing

D)none of the above

Q3) A stack cannot be represented as a linked list.

A)True

B)False

Q4) Given the Node class created in number 6 above,write Java statements to insert a new node containing (Chattanooga,23.7)into an empty list.

Q5) What is the function of the variable head when used with a linked list? What is the data type of the head variable?

Q6) Create a generic Node class to represent the linked list depicted in your diagrams above.

Q7) A queue is a last-in/first-out structure.

A)True

B)False

17

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

Chapter 16: Collections and Iterators

Available Study Resources on Quizplus for this Chatper

44 Verified Questions

44 Flashcards

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

Sample Questions

Q1) The method contains(Object o)of the ArrayList class returns a value of type:

A)int

B)char

C)byte

D)boolean

Q2) If you want a class that implements the List interface and do not need any methods beyond those in the List interface,you can use the ____________ class.

A)Vector< T >

B)LinkedList< T >

C)HashSet< T >

D)TreeSet< T >

Q3) The difference between the List&lt;T&gt; interface and the Set&lt;T&gt; interface is that the Set&lt;T&gt; interface does not impose an order on its unique elements.

A)True

B)False

Q4) What is the purpose of the Java Iterator interface?

Q5) What must you do before adding a primitive type to a vector?

Q6) Write a Java statement to create a vector with initial capacity of 50.

Q7) What is the difference between a vector's size and a vector's capacity?

Page 18

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

Chapter 17: Swing I

Available Study Resources on Quizplus for this Chatper

37 Verified Questions

37 Flashcards

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

Sample Questions

Q1) What are three common objects you must deal with when using a Swing container class?

Q2) Standard layout managers are defined in the ____________ package.

A)javax.swing

B)java.util

C)java.awt

D)java.lang

Q3) In event-driven programming,your program determines the order in which things happen.

A)True

B)False

Q4) What is an action listener? What is an action event?

Q5) The ActionListener interface requires that the method ____________ be implemented.

A)actionEvent()

B)actionFired()

C)actionRegistered()

D)actionPerformed()

Q6) Write a Java statement to add a title to the window in the GUI created in number 1 above that says "First Window".

Page 19

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

Chapter 18: Swing II

Available Study Resources on Quizplus for this Chatper

31 Verified Questions

31 Flashcards

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

Sample Questions

Q1) When the user clicks any of the three standard JFrame buttons,a ___________ is generated.

A)window listener

B)window event

C)window activator

D)window deactivator

Q2) The Graphics class is a(n)____________ class.

A)discrete

B)concrete

C)abstract

D)none of the above

Q3) Java uses a coordinate system whose origin point (0,0)is located at the upper-left corner of the screen area.

A)True

B)False

Q4) All of the following are methods of the class Color except:

A)getRed

B)brighter

C)darker

D)dimmer

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

Chapter 19: Java Never Ends

Available Study Resources on Quizplus for this Chatper

18 Verified Questions

18 Flashcards

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

Sample Questions

Q1) ____________ means that an object has an identity that extends beyond one session.

A)Event handling

B)Introspection

C)Persistence

D)None of the above

Q2) The sleep method of the Thread class requires one formal parameter that represents the number of:

A)nanoseconds

B)microseconds

C)picoseconds

D)milliseconds

Q3) A thread's start method invokes the thread's run method.

A)True

B)False

Q4) What is a JavaBean?

Q5) SQL stands for Structured Query Language.

A)True

B)False

Q6) Discuss the components of the JavaBean model.

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

Chapter 11: Recursion

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

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

Sample Questions

Q1) Write an iterative method to compute the power of x<sup>n</sup> for non-negative n.

Q2) The order of magnitude of the binary search algorithm is:

A)linear

B)exponential

C)logarithmic

D)quadratic

Q3) How does the computer system handle a recursive method call?

Q4) Write a recursive method to print a string backwards.

Q5) Write a recursive method to compute the factorial of a number.

Q6) A method definition that includes a call to itself is said to be recursive.

A)True

B)False

Q7) During recursion,if the stack attempts to grow beyond its limit,a _____________ occurs.

A)Stack underflow

B)Stack overflow

C)Recursive underflow

D)Recursive overflow

Q8) What are the two base cases for a recursive binary search algorithm?

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

Chapter 20: Applets

Available Study Resources on Quizplus for this Chatper

25 Verified Questions

25 Flashcards

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

Sample Questions

Q1) The HTML tag used to insert a horizontal line on a page is:

A)< h1 >

B)< href >

C)< hr >

D)< br >

Q2) Java _____________ were intended to be run over the Internet.

A)applications

B)applets

C)both A and B

D)none of the above

Q3) Write a complete Java applet that displays the phrase "Welcome to my world!" in the center of the applet.

Q4) The purpose of the address tag is to contain the e-mail address for contacting the document's maintainer as well as the date that the document was last modified.

A)True

B)False

Q5) HTML is case sensitive.

A)True

B)False

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

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.