1.
Which statement best describes a computer program?
[Found in Quiz 1]
Correct Answer
D. A program is a sequence of instructions and decisions that the computer carries out.
Explanation
A computer program is a sequence of instructions and decisions that the computer carries out. This means that a program consists of a series of steps or commands that tell the computer what tasks to perform and how to perform them. It can include conditional statements that allow the program to make decisions based on certain conditions. This definition highlights the fact that a program is not limited to performing only one simple task, nor is it simply a sequence of comments. Instead, it encompasses a range of instructions and decisions that enable the computer to execute complex tasks.
2.
What translates high-level descriptions into machine code?
[Appears on Quiz 1]
Correct Answer
D. Compiler
Explanation
A compiler translates high-level descriptions, written in a programming language, into machine code. This process involves converting the entire code into a binary format that can be directly executed by the computer's processor. Unlike an interpreter, which translates and executes the code line by line, a compiler generates an executable file that can be run independently. Linkers, assemblers, and interpreters are also involved in the compilation process, but the compiler is responsible for the main translation of high-level code into machine code.
3.
In Java, every statement must end with this symbol.
[Appears on Quiz 1]
Correct Answer
A. ;
Explanation
In Java, every statement must end with a semicolon (;). This is because the semicolon is used as a delimiter to mark the end of a statement. It is a crucial part of the Java syntax and is required to ensure that the code is properly structured and can be compiled without any errors.
4.
What term is used to refer to a sequence of characters enclosed in quotation marks?
[Appears on Quiz 1]
Correct Answer
B. String
Explanation
A sequence of characters enclosed in quotation marks is referred to as a string. Strings are commonly used to represent text in programming languages. They can include letters, numbers, symbols, and spaces. Strings are often used for storing and manipulating textual data in computer programs.
5.
What is a term used to describe an error detected by the compiler that is a violation of the programming language rules?
[Appears on Quiz 1]
Correct Answer
C. Syntax error
Explanation
A syntax error is a term used to describe an error detected by the compiler that is a violation of the programming language rules. This means that the code written does not follow the proper syntax or grammar of the programming language being used. Syntax errors are typically caught by the compiler during the compilation process and need to be fixed before the code can be executed.
6.
What term is used to refer to a sequence of steps for solving a problem that is unambiguous, executable, and terminating?
[Appears on Quiz 1]
Correct Answer
D. Algorithm
Explanation
An algorithm is a term used to refer to a sequence of steps for solving a problem that is unambiguous, executable, and terminating. It is a well-defined and systematic approach to problem-solving, providing a clear set of instructions to achieve a specific outcome. Algorithms are commonly used in computer science and mathematics to solve complex problems efficiently and effectively. They play a crucial role in various fields, including programming, data analysis, and artificial intelligence.
7.
Which statement about identifiers is correct?
[Appears on Quiz 1]
Correct Answer
C. Identifiers can be made up of letters, digits, and the underscore (_) character.
Explanation
This statement is correct because identifiers in programming languages can indeed be made up of letters, digits, and the underscore (_) character. This allows for a wide range of possibilities when naming variables, functions, or other elements in a program.
8.
What is the result of a % b when variables a and b are declared as follows: int a = 9; int b = 5;?
[Appears in Chap 2 & 4 HW3]
Correct Answer
B. 4
Explanation
The result of a % b when a = 9 and b = 5 is 4. The % operator in programming is called the modulus operator, which returns the remainder of the division between two numbers. In this case, 9 divided by 5 equals 1 with a remainder of 4, so the result is 4.
9.
What is the term that means to put strings together to form a longer string?
[Appears in Chap 2 & 4 HW3]
Correct Answer
A. Concatenation
Explanation
Concatenation refers to the process of combining or joining strings together to form a longer string. It involves taking two or more separate strings and merging them into a single string. This can be done using various programming languages and string manipulation techniques.
10.
What is an object?
[Appears in Quiz 2]
Correct Answer
A. An entity in your program that is manipulated by calling methods.
Explanation
An object is an entity in a program that can be manipulated by calling methods. In object-oriented programming, objects are instances of classes and they have their own set of properties and behaviors defined by the class. Objects allow for the organization and encapsulation of data and functionality, making it easier to manage and manipulate complex systems. By calling methods on an object, we can perform operations and modify its state. This definition accurately describes the concept of an object in programming.
11.
Which of the following statements about methods is correct?
[Appears in Quiz 2]
Correct Answer
A. A method is a sequence of instructions that accesses the data of an object.
Explanation
A method is a sequence of instructions that accesses the data of an object. This means that a method is a set of code that performs a specific task or action on the data associated with an object. It allows us to manipulate and interact with the data within an object by performing operations or calculations. Methods are an essential part of object-oriented programming as they encapsulate the behavior or functionality of an object.
12.
The input to a method is called a(n) _______________.
[Appears in Quiz 2]
Correct Answer
A. Parameter
Explanation
In programming, a method is a block of code that performs a specific task. The input that is passed to a method is called a parameter. Parameters allow us to pass values or data into a method, which can then be used by the method to perform its task. They act as placeholders for the actual values that will be provided when the method is called. Therefore, the correct answer to the question is "parameter".
13.
What is the type of an object?
[Appears in Quiz 2]
Correct Answer
D. Class
Explanation
The correct answer is "class" because an object is an instance of a class. In object-oriented programming, a class is a blueprint for creating objects. Objects are created from classes and they have their own unique set of properties and behaviors defined by the class. Therefore, the type of an object is determined by its class.
14.
The output of a method is called its __________ value.
[Appears in Quiz 2]
Correct Answer
B. Return
Explanation
The output of a method is commonly referred to as its "return" value. This is because when a method is called, it performs a series of operations and then returns a value back to the caller. This value can be used for further processing or stored in a variable. The "return" keyword is used in the method to specify the value that should be returned.
15.
A _____________ is a collection of classes with a related purpose.
[Appears in Quiz 2]
Correct Answer
C. Package
Explanation
A package is a collection of classes with a related purpose. In Java, packages are used to organize and group related classes together. They provide a way to manage the code and make it more modular and reusable. By placing related classes in the same package, it becomes easier to locate and use them in the code. Packages also help in avoiding naming conflicts by providing a unique namespace for classes.
16.
What contains the instructions to initialize the instance variables of an object?
[Appears in Chap 3 HW5]
Correct Answer
D. Constructor
Explanation
A constructor contains the instructions to initialize the instance variables of an object. It is a special method that is automatically called when an object is created. The constructor is responsible for setting the initial values of the object's instance variables, ensuring that the object is properly initialized and ready for use.
17.
The name of the constructor is always the same as the name of the __.
[Appears in Quiz 3]
Correct Answer
C. Class
Explanation
The name of the constructor is always the same as the name of the class. This is because the constructor is a special method that is used to initialize objects of a class. It is called automatically when an object is created, and it has the same name as the class it belongs to. This allows the constructor to be easily identified and called when creating new instances of the class.
18.
A local variable is a variable declared in the...
[Appears on Quiz 3]
Correct Answer
D. Body of a method.
Explanation
A local variable is a variable that is declared within the body of a method. It is only accessible within the scope of that method and cannot be accessed by other methods or classes. Local variables are typically used to store temporary data or intermediate results within a method.
19.
A method is invoked on what type of parameter?
[Appears on Quiz 3]
Correct Answer
D. Implicit parameter
Explanation
When a method is invoked, the implicit parameter refers to the object on which the method is called. It is also known as the calling object or the target object. The implicit parameter is automatically passed to the method when it is called and allows the method to access the properties and behaviors of the object. In other words, the implicit parameter specifies the object that the method is being called on.
20.
You should provide documentation comments for ___.
[Appears on Quiz 3]
Correct Answer
D. Every class, every method, every parameter, and every return value
Explanation
Documentation comments should be provided for every class, every method, every parameter, and every return value. This is important because documentation comments serve as a form of documentation for the code, providing information about the purpose, behavior, and usage of the classes, methods, parameters, and return values. This documentation can be helpful for other developers who may need to understand or use the code in the future, as well as for the original developer who may need to refer back to the code at a later time.
21.
In the statement below, amount is referred to as the ____ parameter.
public void deposit(double amount)
[Appears on Quiz 3]
Correct Answer
D. Explicit
Explanation
In the given statement, the parameter "amount" is referred to as the explicit parameter because it is explicitly stated in the method signature.
22.
A method header consists of these parts: __________________________
[Appears on Quiz 3]
Correct Answer
An access specifier, a return type, a method name, and a list of the parameters (if any).
Explanation
The method header consists of an access specifier, which determines the visibility of the method, a return type, which specifies the type of value that the method returns (if any), a method name, which is the identifier for the method, and a list of parameters (if any), which are the variables that the method accepts as input. These parts together define the signature of the method and allow other parts of the program to call and use the method correctly.
23.
There are 3 items specified in when a method is called. Provide the order of those three items: __________________
[Appeasr on Exam 1]
Correct Answer
object, method name, parameters
Explanation
The order of the three items specified when a method is called is as follows: first, the object on which the method is being called, then the name of the method itself, and finally any parameters that the method requires. This order is important because it allows the program to identify the specific object and method that need to be executed, and to pass any necessary data to the method through the parameters.
24.
Which statement is true about a Java program?
[Appeasr on Exam 1]
Correct Answer
C. Java is case sensitive.
Explanation
Java is case sensitive, meaning that it distinguishes between uppercase and lowercase letters in its syntax. This means that when writing code in Java, the programmer must use the correct capitalization for keywords, variable names, and method names. For example, "System.out.println" is different from "system.out.println". This is an important aspect of the Java language and must be taken into consideration when writing and executing Java programs.
25.
Which operator constructs object instances?
[Appeasr on Exam 1]
Correct Answer
D. New
Explanation
The "new" operator is used in Java to construct object instances. It is followed by the name of the class and parentheses, which can include arguments if necessary. When "new" is used, memory is allocated for the object and the constructor of the class is called to initialize the object. This allows us to create new instances of a class and use them in our program.
26.
What is the output of the following program segment?
int num = 5;
while (num >= 0)
{
num -= 2;
}
System.out.print(num);
[Not seen before]
Correct Answer
B. -1
Explanation
The program segment starts with the variable "num" initialized to 5. The while loop continues as long as "num" is greater than or equal to 0. Inside the loop, "num" is decremented by 2. Since 5 is greater than 0, the loop runs and "num" becomes 3. Then, "num" becomes 1, and finally -1. When the loop condition is checked again, -1 is not greater than or equal to 0, so the loop terminates. The final value of "num" is -1, which is printed as the output.
27.
What is the output from
int n = 12;
System.out.print(goFigure(n));
System.out.print(" " + n);
where the method goFigure is defined as follows:
public double goFigure(int n)
{
n = n % 7;
return (double)(12 / n);
}
[Not seen before]
Correct Answer
D. 2.0 12
Explanation
(double)(12 / 5) results in 2.0 [12 / 5.0 would allow for a result of 2,.4]
and n remains unchanged because it is passed to goFigure by value and the scope changes which n variable it is looking at.
28.
Which of the following statements displays 1234?
I. System.out.print(12 * 100 + 34);
II. System.out.print("12" + 34);
III. System.out.print(12 + "34");
[Not seen before]
Correct Answer
E. I, II, and III
29.
In Java, what reserved word is used to identify constants?
[unseen Wiley Chap 4 question]
Correct Answer
A. Final
Explanation
The reserved word "final" is used in Java to identify constants. In Java, a constant is a variable whose value cannot be changed once it has been assigned. By using the "final" keyword, we can declare a variable as a constant, indicating that its value should remain constant throughout the program.
30.
What is the term that means to explicitly convert a value to a different type?
[unseen Wiley Chap 4 question]
Correct Answer
B. Cast
Explanation
The term "cast" refers to explicitly converting a value to a different type. It is a process where a value of one data type is converted into another data type. This is often done when the programmer wants to perform operations or assignments that require different data types. By using the cast operator, the programmer can specify the desired data type for the value, allowing it to be converted accordingly.
31.
Which of the following code fragments will compile without error?
[unseen Wiley Chap 4 question]
Correct Answer
C. Double balance = 13.75;
int dollars = (int) balance;
Explanation
The code fragment "double balance = 13.75; int dollars = (int) balance;" will compile without error. This is because the variable "balance" is declared as a double and assigned the value 13.75, which is a valid double value. The value of "balance" is then cast to an int and assigned to the variable "dollars". This casting is allowed because it is an explicit cast from a larger data type (double) to a smaller data type (int).
32.
You access array elements with an integer index, using the _____ operator.
Correct Answer
D. {}
Explanation
You access array elements with an integer index, using the get operator.
33.
What type of loop is executed at least once?
Correct Answer
C. Do
Explanation
The do-while loop is executed at least once because the condition is checked at the end of the loop. This means that the code block within the loop will always be executed at least once before the condition is evaluated.
34.
With a __________________ array, keep a companion variable to track how many elements are used.
Correct Answer
D. Partially filled
Explanation
In this context, the term "partially filled" suggests that the array contains some elements, but not all of its elements have been assigned a value. To keep track of the number of elements that have been used, a companion variable is used. This variable helps in determining the actual size or length of the array and allows for efficient memory allocation and manipulation.
35.
Index values of an array list named qInfo range from ______ to ________.
Correct Answer
B. 0, qInfo.size() - 1
Explanation
The index values of an array list named qInfo range from 0 to qInfo.size() - 1. This is because the index of the first element in an array list is 0, and the index of the last element is the size of the array list minus 1. Therefore, the valid index values for qInfo would be 0, 1, 2, ..., qInfo.size() - 1.
36.
-
Rewrite the following traditional for loop header as an enhanced for loop, assuming that ArrayList<String> names has been initialized.
for (int i = 0; i < names.size(); i++)
{
// process name
}
Correct Answer
D. For (String s : names)
Explanation
The correct answer is "for (String s : names)". In an enhanced for loop, the loop variable is declared as the type of the elements in the collection followed by a colon, and then the name of the collection. In this case, the loop variable is "String s" and the collection is "names", which is an ArrayList of Strings. This loop will iterate over each element in the names ArrayList and assign it to the variable "s", allowing for easy processing of each name.
37.
Which method inserts an element in the middle of an array list, increasing its size?
Correct Answer
D. Add method
Explanation
The add method is used to insert an element in the middle of an array list and it also increases the size of the array list. This method allows you to specify the index at which you want to insert the element, and it will shift the existing elements to accommodate the new element. By using the add method, you can effectively insert an element in the middle of the array list and ensure that the size of the list is appropriately increased.
38.
When the body of a loop contains another loop, the loops are __________.
Correct Answer
B. Nested
Explanation
When the body of a loop contains another loop, the loops are referred to as "nested." This means that one loop is enclosed within another loop, creating a hierarchical structure. The outer loop controls the execution of the inner loop, and the inner loop is executed multiple times for each iteration of the outer loop. This nesting allows for more complex and intricate control flow in programming, as different levels of loops can be used to handle different tasks or conditions.
39.
Which statement accesses the first element of an array of strings named sData.
Correct Answer
B. String s = sData[0];
Explanation
The correct answer is "String s = sData[0];". This statement uses square brackets to access the first element of the array named sData. The index inside the square brackets is 0, which represents the first element in the array.