Combo with "CIS 283 Final" and 1 other – Flashcards
Unlock all answers in this set
Unlock answers
question
This is a control structure that causes a statement or group of statements to repeat.
answer
loop
question
This type of loop will always be executed at least once.
answer
post-test loop
question
________ is the process of inspecting data given to the program by the user and determining if it is valid.
answer
input validation
question
This is a value that signals when the end of a list of values has been reached.
answer
sentinel
question
Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?
answer
FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);
question
In all but rare cases, loops must contain within themselves:
answer
A way to terminate.
question
A for loop normally performs which of these steps?
answer
All of these: -Initializes a control variable to a starting value -Tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value -Updates the control variable during each iteration
question
This type of loop is ideal in situations where you always want the loop to iterate at least once.
answer
do-while loop
question
You can use this method to determine whether a file exists.
answer
The File class's exists method
question
The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.
answer
True
question
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
answer
False
question
You can use the PrintWriter class to open a file for writing and write data to it.
answer
True
question
In a for statement, the control variable can only be incremented.
answer
False
question
A file must always be opened before using it and closed when the program is finished using it.
answer
True
question
When you pass the name of a file to the PrintWriter constructor, and the file already exists, it will be erased and a new empty file with the same name will be created.
answer
True
question
Which of the following are classes from the Java API?
answer
All of these: Scanner Random PrintWriter
question
Java allows you to create objects of this class in the same way you would create primitive variables.
answer
String
question
You should not define a class field that is dependent upon the values of other class fields:
answer
In order to avoid having stale data.
question
A constructor:
answer
Has the same name as the class.
question
A class specifies the ________ and ________ that a particular type of object has.
answer
fields, methods
question
In UML diagrams, this symbol indicates that a member is public:
answer
+
question
A constructor is a method that:
answer
Performs initialization or setup operations
question
This is a group of related classes.
answer
package
question
The following package is automatically imported into all Java programs.
answer
java.lang
question
A class in not an object, but a description of an object.
answer
True
question
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator
answer
True
question
A constructor is a method that is automatically called when an object is created.
answer
True
question
A method that gets a value from a class's field but does not change it is known as a mutator method.
answer
False
question
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
answer
False
question
"Shadowing" is the term used to describe where the field name is hidden by the name of a local or parameter variable.
answer
True
question
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
answer
True
question
The increment operator is:
answer
++
question
If a loop does not contain within itself a way to terminate, it is called a(n):
answer
Infinite loop
question
This variable controls the number of times that the loop iterates.
answer
local control variable
question
If you are using a block of statements, don't forget to enclose all of the statements in a set of:
answer
braces
question
This type of loop allows the user to decide the number of iterations.
answer
user controlled loop
question
A loop that repeats a specific number of times is known as a(n):
answer
counter-controlled loop
question
Before entering a loop to compute a running total, the program should first do this.
answer
Set the accumulator where the total will be kept to an initial value, usually zero
question
When using the PrintWriter class, which of the following import statements would you write near the top of your program?
answer
import java.io.*;
question
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?
answer
while (inputFile.hasNext()) (...)
question
Which of the following are pre-test loops?
answer
while, for
question
A loop that executes as long as a particular condition exists is called a(n):
answer
conditional loop
question
A sentinel value ________ and signals that there are no more values to be entered.
answer
is a special value that cannot be mistaken as a member of the list
question
This is an item that separates other items.
answer
delimiter
question
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
answer
int number = inputFile.nextInt();
question
Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrinterWriter diskout = new PrintWriter(DiskFile.txt");
answer
diskOut.println("Calvin");
question
What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", ");
answer
5, 8, 11, 14
question
What will be the value of x after the following code is executed? int x = 10; do ( x*=20; ) while (x < 5);
answer
The loop will not be executed, the initial value of x > 5
question
What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) ( x+=y; y += 20; )
answer
210
question
What will be the value of x after the following code is executed? int x. y = 15, z = 3; x = (y--) / (++z);
answer
5
question
What will be the value of x after the following code is executed? int x = 10; for (int y = 5; y < 20; y =+5) x +=y;
answer
40
question
What will be the value of x after the following code is executed? int x = 10; do ( x *= 20; ) while (x > 5);
answer
this is an infinite loop
question
What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) ( x += y; )
answer
this is an infinite loop
question
What will be the value of x after the following code is executed? int x, y = 4. z = 6; x = (y++) * (++z);
answer
28
question
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }
answer
y is available to code that is written outside the Circle class.
question
In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 || number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); }
answer
Numbers in the range 100 - 500
question
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);
answer
1
question
make sure you are in the same directory or folder where the MyClass.java file is located.
answer
GOF5eMC_CH01_q06. Suppose you are at an operating system command line, and you are going to use the following command to compile a program: Before entering the command, you must
question
the methods that operate on the data.
answer
GOF5eMC_CH01_q07. An object typically hides it data, but allows outside code to access
question
object
answer
GOF5eMC_CH01_q19. A(n) ________ is a software entity that contains data and procedures.
question
8
answer
GOF5eMC_CH01_q27. How many bits are in a byte?
question
java ReadIt
answer
GOF5eMC_CH01_q02. Which of the following commands will run the compiled Java program named ReadIt?
question
symbolic names made up by the programmer that represents locations in the computer's RAM.
answer
GOF5eMC_CH01_q09. Variables are
question
data hiding
answer
GOF5eMC_CH01_q12. A characteristic of ________ is that only an object's methods are able to directly access and make the changes to the object's data.
question
are highly portable.
answer
GOF5eMC_CH01_q13. Because Java byte code is the same on all computers, compiled Java programs
question
read and interpreted by the JVM.
answer
GOF5eMC_CH01_q15. Byte code instructions are
question
words that have a special meaning in the programming language.
answer
GOF5eMC_CH01_q17. Key words are
question
Rules that must be followed when writing a program.
answer
GOF5eMC_CH01_q23. What is syntax?
question
attributes.
answer
GOF5eMC_CH01_q30. The data contained in an object is known as
question
'True'.
answer
GOF5eTF_CH01_q02. The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.
question
'True'.
answer
GOF5eTF_CH01_q07. Encapsulation refers to the combining of data and code into a single object.
question
'False'.
answer
GOF5eTF_CH01_q08. Java source files end with the .class extension.
question
.java.
answer
GOF5eMC_CH02_q02. When saving a Java source file, save it with an extension of
question
Identifiers can contain spaces.
answer
GOF5eMC_CH02_q04. Which of the following is not a rule that must be followed when naming identifiers?
question
7
answer
GOF5eMC_CH02_q06. What is the result of the following expression?
question
5
answer
GOF5eMC_CH02_q08. What is the result of the following expression?
question
x = (float)y;
answer
GOF5eMC_CH02_q10. Which of the following statements will correctly convert the data type, if x is a float and y is a double?
question
x = 37, y = 5
answer
GOF5eMC_CH02_q12. What output will be displayed as a result of executing the following code?
question
double r = 2.9X106;
answer
GOF5eMC_CH02_q14. Which of the following statements is invalid?
question
evaluating conditions that are either true or false.
answer
GOF5eMC_CH02_q16. Variables of the boolean data type are useful for
question
the memory address where "John Doe" is located
answer
GOF5eMC_CH02_q18. In the following Java statement what value is stored in the variable name?
question
class definition.
answer
GOF5eMC_CH02_q20. A Java program must have at least one
question
Scanner keyboard = new Scanner(System.in);
answer
GOF5eMC_CH02_q22. Which of the following statements correctly creates a Scanner object for keyboard input?
question
variable
answer
GOF5eMC_CH02_q24. The primitive data types only allow a(n) ________ to hold a single value.
question
import javax.swing.JOptionPane;
answer
GOF5eMC_CH02_q26. This statement tells the compiler where to find the JOptionPane class and makes it available to your program.
question
input dialog
answer
GOF5eMC_CH02_q28. A(n) ________ is a dialog box that prompts the user for input.
question
%s
answer
GOF5eMC_CH02_q30. If you wish to use the System.out.printf method to print a string argument, use the ________ format specifier.
question
'True'.
answer
GOF5eTF_CH02_q01. Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.
question
'False'.
answer
GOF5eTF_CH02_q02. Both character literals and string literals can be assigned to a char variable.
question
'True'.
answer
GOF5eTF_CH02_q03. A variable's scope is the part of the program that has access to the variable.
question
'True'.
answer
GOF5eTF_CH02_q04. Named constants are initialized with a value, and that value cannot change during the execution of the program.
question
'True'.
answer
GOF5eTF_CH02_q05. When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.
question
'False'.
answer
GOF5eTF_CH02_q06. A message dialog is a quick and simple way to ask the user to enter data.
question
'True'.
answer
GOF5eTF_CH02_q07. The Java API provides a class named Math, which contains numerous methods that are useful for performing complex mathematical operations.
question
'True'.
answer
GOF5eTF_CH02_q08. Unlike a console program, a program that uses JOptionPane does not automatically stop executing when the end of the main method is reached.
question
'True'.
answer
GOF5eTF_CH02_q09. The System.out.printf method allows you to format output in a variety of ways.
question
'True'.
answer
GOF5eTF_CH02_q10. If you use a flag in a format specifier, you must write the flag before the field width and the precision.
question
both the things a class is responsible for knowing and the things a class is responsible for doing
answer
GOF5eMC_CH03_q02. A class's responsibilities include
question
instance methods.
answer
GOF5eMC_CH03_q04. Methods that operate on an object's fields are called
question
methods
answer
GOF5eMC_CH03_q06. Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
question
objects
answer
GOF5eMC_CH03_q08. In the blueprint/house analogy, think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.
question
a public method with a parameter of data type double that does not return a value
answer
GOF5eMC_CH03_q10. What does the following UML diagram entry mean?
question
the method in which they are defined.
answer
GOF5eMC_CH03_q12. The scope of a local variable is
question
may have zero or more parameter variables.
answer
GOF5eMC_CH03_q14. A method
question
The z field is available to code that is written outside the Sphere class.
answer
GOF5eMC_CH03_q16. For the following code, which statement is not true?
question
object names.
answer
GOF5eMC_CH03_q18. UML diagrams do not contain
question
creates an object in memory.
answer
GOF5eMC_CH03_q20. The key word new
question
braces, {}.
answer
GOF5eMC_CH03_q22. After the header, the body of the method appears inside a set of
question
The y field is available to code that is written outside the Circle class.
answer
GOF5eMC_CH03_q24. For the following code, which statement is not true?
question
the variable name followed by a colon and the data type.
answer
GOF5eMC_CH03_q26. To indicate the data type of a variable in a UML diagram, you specify
question
the parameter variable holds the address of the argument.
answer
GOF5eMC_CH03_q28. When an argument is passed by value,
question
be automatically initialized with 0.
answer
GOF5eMC_CH03_q30. If you do not provide initialization values for a class's numeric fields, they will
question
'True'.
answer
GOF5eTF_CH03_q01. An access specifier indicates how the class may be accessed.
question
'False'.
answer
GOF5eTF_CH03_q02. A method that gets a value from a class's field but does not change it is known as a mutator method.
question
'True'.
answer
GOF5eTF_CH03_q03. The term "no-arg constructor" is applied to any constructor that does not accept arguments.
question
'False'.
answer
GOF5eTF_CH03_q04. When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
question
'False'.
answer
GOF5eTF_CH03_q05. The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
question
'False'.
answer
GOF5eTF_CH03_q06. The term "default constructor" is applied to the first constructor written by the author of the class.
question
'True'.
answer
GOF5eTF_CH03_q07. A method that stores a value in a class's field or in some other way changed the value of a field is known as a mutator method.
question
'True'.
answer
GOF5eTF_CH03_q08. A constructor is a method that is automatically called when an object is created.
question
'True'.
answer
GOF5eTF_CH03_q09. The java.lang package is automatically imported into all Java programs.
question
'True'.
answer
GOF5eTF_CH03_q10. Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
question
str1.equals(str2)
answer
GOF5eMC_CH04_q01. If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
question
the statement or block following the else is executed.
answer
GOF5eMC_CH04_q02. In an if-else statement, if the boolean expression is false
question
ans = 60, x = 0, y = 50
answer
GOF5eMC_CH04_q03. What will be the values of ans, x, and y after the following statements are executed?
question
15
answer
GOF5eMC_CH04_q05. What will be the value of x after the following code is executed?
question
1000
answer
GOF5eMC_CH04_q06. What will be the value of bonus after the following code is executed?
question
0.0
answer
GOF5eMC_CH04_q07. What would be the value of discountRate after the following statements are executed?
question
Relational
answer
GOF5eMC_CH04_q09. ________ operators are used to determine whether a specific relationship exists between two values.
question
0.04
answer
GOF5eMC_CH04_q10. What would be the value of discountRate after the following statements are executed?
question
str1.equalsIgnoreCase(str2)
answer
GOF5eMC_CH04_q11. Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
question
The code contains an error and will not compile.
answer
GOF5eMC_CH04_q14. What is the value of ans after the following code has been executed?
question
braces.
answer
GOF5eMC_CH04_q15. A block of code is enclosed in a set of
question
The code contains an error and will not compile.
answer
GOF5eMC_CH04_q16. What will be displayed after the following code has been executed?
question
40
answer
GOF5eMC_CH04_q18. What will be displayed when the following code is executed?
question
true or false.
answer
GOF5eMC_CH04_q19. The boolean expression in an if statement must evaluate to
question
true or false.
answer
GOF5eMC_CH04_q20. A flag may have the values
question
chrA != 'A'
answer
GOF5eMC_CH04_q22. Which of the following expressions determines whether the char variable chrA is not equal to the letter 'A'?
question
a block of statements.
answer
GOF5eMC_CH04_q23. Enclosing a group of statements inside a set of braces creates
question
flag
answer
GOF5eMC_CH04_q25. A ________ is a boolean variable that signals when some condition exists in the program.
question
x <= y
answer
GOF5eMC_CH04_q26. Which of the following expressions will determine whether x is less than or equal to y?
question
if
answer
GOF5eMC_CH04_q27. The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.
question
Unicode number
answer
GOF5eMC_CH04_q28. When a character is stored in memory, it is actually the ________ that is stored.
question
a set of parentheses.
answer
GOF5eMC_CH04_q29. Java requires that the boolean expression being tested by an if statement be enclosed in
question
if (temp >= 0 && temp <= 100)
answer
GOF5eMC_CH04_q30. Which of the following statements determines whether temp is within the range of 0 through 100?
question
'True'.
answer
GOF5eTF_CH04_q01. An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.
question
'True'.
answer
GOF5eTF_CH04_q02. The if-else statement will execute one group of statements if its boolean expression is true, or another group if its boolean expression is false.
question
'True'.
answer
GOF5eTF_CH04_q04. A local variable's scope always ends at the closing brace of the block of code in which it is declared.
question
'True'.
answer
GOF5eTF_CH04_q05. Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
question
'True'.
answer
GOF5eTF_CH04_q06. All it takes for an OR expression to be true is for one of the subexpressions to be true.
question
'False'.
answer
GOF5eTF_CH04_q08. When two strings are compared using the String class's compareTo method, the comparison is case-insensitive.
question
'True'.
answer
GOF5eTF_CH04_q10. If the expression on the left side of the ;; operator is false, the expression on the right side will not be checked.
question
Tree.PINE
answer
GOF5eMC_CH06_q29. Look at the following declaration: What is the fully-qualified name of the PINE enum constant?
question
"Has a"
answer
GOF5eMC_CH06_q07. ________ is the term for the relationship created by object aggregation.
question
This is a public method that accepts a Stock object as its argument and returns a boolean value.
answer
GOF5eMC_CH06_q15. If the following is from the method section of a UML diagram, which of the following statements is true?
question
only one copy of the field in memory.
answer
GOF5eMC_CH06_q27. When a field is declared static, there will be
question
SavingsAccount.getNumberOfAccounts();
answer
GOF5eMC_CH06_q03. If you have defined a class SavingsAccount with a public static method getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method?
question
Class, Responsibilities, Collaborations.
answer
GOF5eMC_CH06_q23. CRC stands for
question
aggregate
answer
GOF5eMC_CH06_q19. When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent "security holes."
question
it must be the first statement in the constructor making the call.
answer
GOF5eMC_CH06_q13. When the this variable is used to call a constructor
question
null.
answer
GOF5eMC_CH06_q17. By default, a reference variable that is an instance field is initialized to the value
question
True
answer
GOF5eTF_CH06_q09. When an object is passed as an argument, it is actually a reference to the object that is passed.
question
True
answer
GOF5eTF_CH06_q05. An instance of a class does not have to exist in order for values to be stored in a class's static fields.
question
True
answer
GOF5eTF_CH06_q01. The key word this is the name of a reference variable that an object can use to refer to itself.
question
having two or more methods with the same name, but different signatures.
answer
GOF5eMC_CH06_q09. Overloading is
question
the method name and the parameter list.
answer
GOF5eMC_CH06_q11. A method's signature consists of
question
procedural programming, object-oriented programming
answer
GOF5eMC_CH01_q01. Whereas ________ is centered on creating procedures, ________ is centered on creating objects.
question
Semicolons
answer
GOF5eMC_CH01_q22. ________ are used to indicate the end of a Java statement.
question
'True'.
answer
GOF5eTF_CH01_q02. The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.
question
symbolic names made up by the programmer that represents locations in the computer's RAM.
answer
GOF5eMC_CH01_q09. Variables are
question
are highly portable.
answer
GOF5eMC_CH01_q13. Because Java byte code is the same on all computers, compiled Java programs
question
procedural and object-oriented.
answer
GOF5eMC_CH01_q04. The two primary methods of programming in use today are
question
read and interpreted by the JVM.
answer
GOF5eMC_CH01_q15. Byte code instructions are
question
'True'.
answer
GOF5eTF_CH01_q07. Encapsulation refers to the combining of data and code into a single object.
question
8
answer
GOF5eMC_CH01_q27. How many bits are in a byte?
question
object
answer
GOF5eMC_CH01_q19. A(n) ________ is a software entity that contains data and procedures.
question
make sure you are in the same directory or folder where the MyClass.java file is located.
answer
GOF5eMC_CH01_q06. Suppose you are at an operating system command line, and you are going to use the following command to compile a program: Before entering the command, you must
question
Pseudocode
answer
GOF5eMC_CH01_q14. ________ is a cross between human language and a programming language.
question
a set of instructions that enable the computer to solve a problem or perform a task.
answer
GOF5eMC_CH01_q25. A computer program is
question
'False'.
answer
GOF5eTF_CH01_q08. Java source files end with the .class extension.
question
data hiding
answer
GOF5eMC_CH01_q12. A characteristic of ________ is that only an object's methods are able to directly access and make the changes to the object's data.
question
'True'.
answer
GOF5eTF_CH01_q01. Logical errors are mistakes that cause the program to produce erroneous results.
question
the methods that operate on the data.
answer
GOF5eMC_CH01_q07. An object typically hides it data, but allows outside code to access
question
java ReadIt
answer
GOF5eMC_CH01_q02. Which of the following commands will run the compiled Java program named ReadIt?
question
'False'.
answer
GOF5eTF_CH01_q03. Colons are used to indicate the end of a Java statement.
question
words that have a special meaning in the programming language.
answer
GOF5eMC_CH01_q17. Key words are
question
Rules that must be followed when writing a program.
answer
GOF5eMC_CH01_q23. What is syntax?
question
attributes.
answer
GOF5eMC_CH01_q30. The data contained in an object is known as
question
true or false.
answer
GOF5eMC_CH02_q11. The boolean data type may contain the following range of values:
question
with only a format string, and no additional arguments.
answer
GOF5eMC_CH02_q29. The simplest way you can use the System.out.printf method is
question
showMessageDialog
answer
GOF5eMC_CH02_q27. The ________ method is used to display a message dialog.
question
'True'.
answer
GOF5eTF_CH02_q07. The Java API provides a class named Math, which contains numerous methods that are useful for performing complex mathematical operations.
question
nextLine
answer
GOF5eMC_CH02_q25. Which Scanner class method reads a String?
question
'True'.
answer
GOF5eTF_CH02_q05. When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.
question
data type.
answer
GOF5eMC_CH02_q09. Variables are classified according to their
question
System.out.println("Hello, world");
answer
GOF5eMC_CH02_q15. To print "Hello, world" on the monitor, use the following Java statement:
question
8.0
answer
GOF5eMC_CH02_q07. What will be the value of z after the following statements have been executed?
question
x = 27, y = 3, z = 18
answer
GOF5eMC_CH02_q21. What will be displayed after the following statements have been executed?
question
(asterisk)/ Comment 2 /(asterisk)
answer
GOF5eMC_CH02_q01. Which of the following is not a valid Java comment?
question
5.0
answer
GOF5eMC_CH02_q23. What will be the value of z as a result of executing the following code?
question
There are 5785 (tab)hens in the hen house.
answer
GOF5eMC_CH02_q17. What would be displayed as a result of the following code?
question
Variable
answer
GOF5eMC_CH02_q13. This is a named storage location in the computer's memory.
question
'True'.
answer
GOF5eTF_CH02_q03. A variable's scope is the part of the program that has access to the variable.
question
'True'.
answer
GOF5eTF_CH02_q09. The System.out.printf method allows you to format output in a variety of ways.
question
'True'.
answer
GOF5eTF_CH02_q01. Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.
question
single quotes, double quotes
answer
GOF5eMC_CH02_q05. Character literals are enclosed in ________, and string literals are enclosed in ________.
question
Nothing. There is an error in the code.
answer
GOF5eMC_CH02_q19. What will be the displayed when the following code is executed?
question
Literal
answer
GOF5eMC_CH02_q03. This is a value that is written into the code of a program.
question
instance fields.
answer
GOF5eMC_CH03_q01. When an object is created, the attributes associated with the object are called
question
using the private access specifier on the class fields.
answer
GOF5eMC_CH03_q03. Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by
question
package.
answer
GOF5eMC_CH03_q05. A group of related classes is called a(n)
question
in order to avoid having stale data.
answer
GOF5eMC_CH03_q07. You should not define a class field that is dependent upon the values of other class fields
question
+
answer
GOF5eMC_CH03_q09. In UML diagrams, what symbol indicates that a member is public?
question
instance.
answer
GOF5eMC_CH03_q11. Another term for an object of a class is a(n)
question
Write the code.
answer
GOF5eMC_CH03_q13. Which of the following is not involved in finding the classes when developing an object-oriented application?
question
performs initialization or setup operations.
answer
GOF5eMC_CH03_q15. A constructor is a method that
question
fields private.
answer
GOF5eMC_CH03_q17. It is common practice in object-oriented programming to make all of a class's
question
import
answer
GOF5eMC_CH03_q19. You use this key word to import a class.
question
an explicit import statement
answer
GOF5eMC_CH03_q21. What is the following statement an example of?
question
a wildcard import statement
answer
GOF5eMC_CH03_q23. What is the following statement an example of?
question
class.
answer
GOF5eMC_CH03_q25. One or more objects may be created from a(n)
question
has the same name as the class.
answer
GOF5eMC_CH03_q27. A constructor
question
-
answer
GOF5eMC_CH03_q29. A UML diagram uses the ________ symbol to indicate that a member is private.
question
'True'.
answer
GOF5eTF_CH03_q01. An access specifier indicates how the class may be accessed.
question
'True'.
answer
GOF5eTF_CH03_q03. The term "no-arg constructor" is applied to any constructor that does not accept arguments.
question
'False'.
answer
GOF5eTF_CH03_q05. The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
question
'True'.
answer
GOF5eTF_CH03_q07. A method that stores a value in a class's field or in some other way changed the value of a field is known as a mutator method.
question
'True'.
answer
GOF5eTF_CH03_q09. The java.lang package is automatically imported into all Java programs.
question
both the things a class is responsible for knowing and the things a class is responsible for doing
answer
GOF5eMC_CH03_q02. A class's responsibilities include
question
instance methods.
answer
GOF5eMC_CH03_q04. Methods that operate on an object's fields are called
question
methods
answer
GOF5eMC_CH03_q06. Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
question
objects
answer
GOF5eMC_CH03_q08. In the blueprint/house analogy, think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.
question
a public method with a parameter of data type double that does not return a value
answer
GOF5eMC_CH03_q10. What does the following UML diagram entry mean?
question
a volatile type of memory, used only for temporary storage.
answer
GOF5eMC_q03. RAM is usually
question
determine if the program solves the original problem.
answer
GOF5eMC_q05. The purpose of validating the results of the program is to
question
Hardware
answer
GOF5eMC_q11. ________ refers to the physical components that a computer is made of.
question
the programs that make the computer useful to the user.
answer
GOF5eMC_q21. Application software refers to
question
Programming language
answer
GOF5eMC_q29. This is a special language used to write computer programs.
question
100
answer
GOF5eMC_CH05_q01. What will be the value of x after the following code is executed?
question
posttest
answer
GOF5eMC_CH05_q03. This type of loop will always be executed at least once.
question
sentinel
answer
GOF5eMC_CH05_q05. A ________ is a value that signals when the end of a list of values has been reached.
question
import java.io.*;
answer
GOF5eMC_CH05_q07. When working with the PrintWriter class, which of the following import statements should you have near the top of your program?
question
1
answer
GOF5eMC_CH05_q09. How many times will the following do-while loop be executed?
question
FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);
answer
GOF5eMC_CH05_q11. Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
question
40
answer
GOF5eMC_CH05_q13. What will be the value of x after the following code is executed?
question
the File class's exists method
answer
You can use this method to determine whether a file exists.
question
Nothing. The code contains a syntax error.
answer
GOF5eMC_CH05_q19. What does the following code do?
question
File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
answer
GOF5eMC_CH05_q23. Which of the following statements opens a file named MyFile.txt and allows you to read data from it?
question
an infinite loop.
answer
GOF5eMC_CH05_q25. If a loop does not contain within itself a way to terminate, it is called
question
sentinel
answer
GOF5eMC_CH05_q27. A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items from the list to be processed.
question
accumulator.
answer
GOF5eMC_CH05_q29. The variable used to keep the running total is called a(n)
question
posttest
answer
GOF5eMC_q03. This type of loop will always be executed at least once.
question
sentinel
answer
GOF5eMC_q05. A ________ is a value that signals when the end of a list of values has been reached.
question
the File class's exists method
answer
GOF5eMC_q15. You can use this method to determine whether a file exists.
question
The code contains a syntax error.
answer
GOF5eMC_q19. What does the following code do?
question
accumulator
answer
GOF5eMC_q29. The variable used to keep the running total is called a(n)
question
sentinel
answer
GOF5eMC_q27. A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items from the list to be processed.
question
str1.equals(str2)
answer
GOF5eMC_CH04_q01. If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
question
braces
answer
GOF5eMC_CH04_q15. A block of code is enclosed in a set of
question
"000.0"
answer
GOF5eMC_CH04_q17. Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 012.8?
question
true or false.
answer
GOF5eMC_CH04_q19. The boolean expression in an if statement must evaluate to
question
300.0
answer
GOF5eMC_CH04_q21. What will be displayed after the following statements are executed?
question
a block of statements.
answer
GOF5eMC_CH04_q23. Enclosing a group of statements inside a set of braces creates
question
flag
answer
GOF5eMC_CH04_q25. A ________ is a boolean variable that signals when some condition exists in the program.
question
if
answer
GOF5eMC_CH04_q27. The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.
question
a set of parentheses.
answer
GOF5eMC_CH04_q29. Java requires that the boolean expression being tested by an if statement be enclosed in
question
'True'.
answer
GOF5eTF_CH04_q01. An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.
question
'False'.
answer
GOF5eTF_CH04_q03. In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
question
'True'.
answer
GOF5eTF_CH04_q05. Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
question
'True'.
answer
GOF5eTF_CH04_q07. The DecimalFormat class is part of the Java API, but it is not automatically available to your programs.
question
'False'.
answer
GOF5eTF_CH04_q09. When testing for character values, the switch statement does not test for the case of the character.
question
1+1
answer
666 CH4
question
true
answer
In a for loop, the control variable can only be incremented.
question
Set the accumulator where the total will be kept to an initial value, usually zero
answer
Before entering a loop to compute a running total, the program should first
question
x = 17, y = 4
answer
What will be the values of x and y as a result of the following code? nt x = 12, y = 5; x += y- -;
question
false
answer
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
question
false
answer
In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.
question
Counter-controlled loop
answer
A loop that repeats a specific number of times is known as a(n) ________.
question
Running total
answer
This is a sum of numbers that accumulates with each iteration of a loop
question
Delimiter
answer
This is an item that separates other items.
question
true
answer
When you open a file with the PrintWriter class, the class can potentially throw an IOException.
question
An infinite loop
answer
If a loop does not contain within itself a way to terminate, it is called
question
int number = inputFile.nextInt();*****
answer
Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?
question
Conditional loop
answer
A loop that executes as long as a particular condition exists is called a(n) ________.
question
All of the above**
answer
A for loop normally performs which of these steps?
question
40
answer
What will be the value of x after the following code is executed? int x = 10; for (int y = 5; y < 20; y +=5) x += y;
question
false
answer
The do-while loop is a pre-test loop.
question
true
answer
The do-while loop must be terminated with a semicolon.
question
It is a sentinel
answer
Look at the following code: Scanner keyboard = new Scanner(System.in); int studentGrade = 0; int totalOfStudentGrades = 0; while(studentGrade != -1) { System.out.println("Enter student grade: :"); studentGrade = keyboard.nextInt(); totalOfStudentGrades += studentGrade; } In the loop header: while(studentGrade != -1), what is the purpose of "-1"
question
Sentinel
answer
This is a value that signals when the end of a list of values has been reached.
question
false
answer
When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.
question
5
answer
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100);
question
x = 33, y = 9
answer
What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;
question
This is an infinite loop
answer
What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; }
question
1
answer
How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);
question
for loop
answer
This type of loop is ideal in situations where the exact number of iterations is known.
question
File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);
answer
Which of the following will open a file named MyFile.txt and allow you to read data from it?
question
2+2
answer
666 CH4
question
true
answer
The expression in a return statement can be any expression that has a value.
question
true
answer
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
question
All of the above are benefits
answer
Which of the following is not a benefit derived from using methods in programming?
question
void
answer
This type of method performs a task and then terminates.
question
true
answer
Constants, variables, and the values of expressions may be passed as arguments to a method.
question
Declared in the method header inside the parentheses
answer
When an argument value is passed to a method, the receiving parameter variable is
question
true
answer
A value-returning method can return a reference to a non-primitive type.
question
The @return tag
answer
To document the return value of a method, use this in a documentation comment.
question
displayValue(a,b); // where a is a short and b is a long
answer
Given the following method header, which of the method calls would be an error? public void displayValues(double x, int y)
question
Appear after the general description of the method
answer
All @param tags in a method's documentation comment must
question
true
answer
Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.
question
All of the above are benefits
answer
Which of the following is not a benefit derived from using methods in programming?
question
Actually a reference to the object that is passed
answer
When an object, such as a String, is passed as an argument, it is
question
true
answer
A parameter variable's scope is the method in which the parameter is declared.
question
semicolon
answer
Which of the following is not a part of the method header?
question
true
answer
No statement outside the method in which a parameter variable is declared can access the parameter by its name.
question
A void method
answer
In the following code, System.out.println(num), is an example of ________. double num = 5.4; System.out.println(num); num = 0.0;
question
Method body
answer
This part of a method is a collection of statements that are performed when the method is executed.
question
The data type of the return value
answer
The header of a value-returning method must specify this.
question
all of the above
answer
Breaking a program down into small manageable methods
question
true
answer
You must have a return statement in a value-returning method.
question
The data type of the argument x should not be included in the method call
answer
What is wrong with the following method call? displayValue (double x);
question
The last line of code will cause an error
answer
What will be the result of the following code? int num; string str = "555"; num = Integer.parseInt(string str) + 5;
question
showProduct(10, 4.5);
answer
Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); }
question
showProduct(3.3, 55);
answer
Which of the following would be a valid method call for the following method? public static void showProduct(double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); }
question
@param tag
answer
When writing the documentation comments for a method, you can provide a description of each parameter by using a
question
3+3
answer
666 CH6
question
true
answer
Instance methods do not have the key word static in their headers.
question
(1) String str = new String("Hello, world"); (2) String str = "Hello, world"; ==Both 1 and 2
answer
Which of the following statements will create a reference, str, to the string, "Hello, world"?
question
fields private
answer
It is common practice in object-oriented programming to make all of a class's
question
instance
answer
Another term for an object of a class is a(n)
question
class
answer
One or more objects may be created from a(n)________.
question
Encapsulation
answer
This refers to the combining of data and code into a single object.
question
String str = "Hello, World";
answer
Which of the following statements will create a reference, str, to the String, "Hello, World"?
question
There is no value because the object order has not been created
answer
Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public int getOrderAmount() { return orderAmount; } public int getOrderDisc() { return orderDisc; } } public class CustomerOrder { public static void main(String[] args) { int ordNum = 1234; double ordAmount = 580.00; double discountPer = .1; Order order; double finalAmount = order.getOrderAmount() — order.getOrderAmount() * order.getOrderDisc(); System.out.println("Final order amount = $" + finalAmount); } }
question
java.lang
answer
The following package is automatically imported into all Java programs.
question
the instance methods of the same class
answer
The scope of a private instance field is
question
A wildcard import
answer
Look at the following statement. import java.util.*; This is an example of
question
The variable name followed by a colon and the data type
answer
In a UML diagram to indicate the data type of a variable enter
question
instance fields
answer
When an object is created, the fields associated with the object are called
question
Class name; fields; methods
answer
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _________; the middle section holds _________; the bottom section holds _________.
question
true
answer
A constructor is a method that is automatically called when an object is created.
question
fields private
answer
It is common practice in object-oriented programming to make all of a class's
question
java.lang
answer
The following package is automatically imported into all Java programs
question
Braces, {}
answer
After the header, the body of the method appears inside a set of
question
object names
answer
A UML diagram does not contain ________.
question
This is a public method with a parameter of data type double and does not return a value
answer
What does the following UML diagram entry mean? + setHeight(h : double) : void
question
+
answer
In UML diagrams, this symbol indicates that a member is public.
question
Both A and B
answer
A class's responsibilities include
question
y is available to code that is written outside the Circle class
answer
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }
question
4+4
answer
666 Java CH 2