1/238
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What operator is used to perform string concatenation in Java?
+
If a String variable called greeting contains the characters "hello", what does the expression greeting.toUpperCase() accomplish?
Returns a new string containing the characters "HELLO"
If a String variable called pioneer contains the characters "Grace Murray Hopper", what is the result of the expression pioneer.length()?
19
Given the following declaration, which expression would produce the substring "ledge"?
String words = "Knowledge is power.";words.substring(4,9);
What output would be produced when the following code is executed?
String state = "Mississippi";
System.out.println(state.replace("is", "was"));Mwasswassippi
If a String variable called address contains the characters "123 Main Street", what is the result of the expression address.indexOf('3')?
2
Which of the following is the preferred way to declare an array.
double[] prices = new double[10];
What is the output of the following code?
int sum = 0;
int[] values = {7, 6, 5, 4, 3, 2, 1};
for (int i = 1; i < values.length; i++)
sum += values[i];
System.out.println("Sum: " + sum);Sum: 21
What is the output of the following code?
int sum = 0;
int[] values = {1, 2, 3, 4, 5};
for (int i = 0; i <= 5; i++)
sum = sum + values[i];
System.out.println("Sum: " + sum);No output. A bounds error occurs.
What is the output of the following code?
int[] list = new int[5];
System.out.println(list[3]);0
Arrays can hold primitive types, but not objects.
False
If you try to access an element outside of the valid index range for an array, an exception will be thrown.
True
If an array can hold N values, the valid indexes for that array range from 0 to N.
False
What output is produced by the following code?
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
System.out.print("*");
System.out.println();
}*****
*****
*****
*****
*****
What does the following for loop do?
for (int num = 3; num <= 30; num += 3)
System.out.println(num);Print the multiples of 3 between 3 and 30 (3,6,9, etc.)
6
What value is printed by the following code?
int count = 0;
for (int i = 0; i < 5; i++)
count += 3;
System.out.println(count);15
Going from left to right, what are the three sections of a for loop header?
initialization, condition, increment
A for loop could always be written as an equivalent while loop.
True
The increment section of the for loop header always adds 1 to the loop control variable.
False
The body of a for loop is always executed at least once.
False
The control variable must be declared in the for loop header.
False
Swapping two elements in an array requires three assignment statements.
True
To change the algorithm for finding a minimum value into one that finds a maximum value, the condition of the for loop would change.
False
A linear search examines every element in the array.
False
Finding a minimum value requires that every element in the array be considered.
True
A for-each loop can be used to compute the sum of all values in an array.
True
A for-each loop can be used to fill the values in an array.
False
Trying to run a program in Eclipse without first saving it will cause it to crash.
False
Eclipse displays code using syntax highlighting.
True
The output of a Java program run in Eclipse appears in the package explorer view.
False
Compiling a program that contains syntax errors will cause Eclipse to fix the errors.
False
Eclipse is best described as which of the following?
Integrated Development Environment (IDE)
Which of the following is an appropriate analogy?
Class: concept of a dog, Object: my dog Fido
Which of the following is an example of the state of a Car object?
The car’s color
Each object has its own instance data.
True
The values of an object's instance data represent the object's identity.
false
A class represents a group of similar objects.
True
A String method can be called through a string literal.
True
A String object cannot be created using the new operator.
False
Attempting to follow a null reference will cause an exception to be thrown.
True
An object must be created when its object reference variable is declared.
False
A constructor of a class has the same name as the class.
True
The Java keyword new is a method that can be called to create objects.
False
The toString method returns a textual description of an object.
True
The methods of a class that can be called from other classes make up its public interface.
True
All Java classes have a main method.
False
Encapsulation ensures that an object controls its own data.
True
Instance data is shared by all objects of a class.
False
An object created from a class is called an instance of that class.
True
A constructor is a programming construct that contains data and methods.
False
A variable can be declared inside the body of a method.
True
If the type of the expression in a return statement does not match the return type of the method, the compiler will issue an error message.
True
The return type of a method must either be a Java primitive type or void.
False
It is usually not a good idea to explicitly return a true or false literal value in a method that returns a boolean value.
True
A method that has a return type of void does not have to have a return statement.
True
When a method is called, the type and value of each argument are included in parentheses.
False
A method declaration includes parentheses after the method name, even if the method takes no parameters.
True
What is the output of the following code?
Die die = new Die(20);
die.roll();
die.roll();
System.out.println(die.getValue());A random number between 1 and 20.
What is the output of the following code?
Die die = new Die(6);
System.out.println("Die value: " + die);Die value: 1
The parameter to the constructor of the Die class determines how many sides are on the die.
True
Each time the roll method is called, a random value is picked as the new face value.
True
The maximum number of sides on a Die object is 20.
False
The Die class is part of the Java API.
False
The package of any class that is declared without an explicit package statement.
default package
A group of related classes.
package
The first line of code in a source file that declares which package the class is in.
package statement
A way to refer to a class that includes its complete package name.
fully qualified name
The set of directories that are searched to find a class.
classpath
A feature of packages that enables two classes to have the same name.
name space
The String class is part of the java.util package.
False
Two classes can have the same name if they are in different packages.
True
In a program, a class must always be referred to using its fully qualified name.
False
An import statement tells the compiler which class you're referring to in a program.
True
An import statement should be written inside a class but before any methods.
False
The classes of the java.util package are automatically imported into every Java program.
False
An entire package can be imported using one import statement.
True
A static import lets you refer to a static method without using its class name.
True
Block tags are enclosed in { } braces and appear anywhere in a Javadoc comment.
False
Javadoc comments start with // for single-line comments and /** for multiple-line comments.
False (/** and */)
The @return tag describes the parameters passed to a method or constructor.
False
The Java API is generated from Javadoc comments.
True
The classic format for a getter method is to use the word "access" in front of the variable name.
False
A method can only be an accessor or a mutator but not both.
False
Encapsulation makes is difficult for hackers to access your data.
False
Classes should be designed to have well-defined and limited interactions with other classes.
True
Constants can be declared with public visibility without violating encapsulation.
True
An encapsulated object keeps other objects from changing the values of its instance data.
True
Assuming table is a two-dimensional array of integers, what does the following code do?
int sum = 0;
for (int i = 0; i < table.length; i++)
for (int j = 0; j < table[i].length; j++)
sum = sum + table[i][j];Computes the sum of all values in the table.
Which line of code demonstrates a valid and error-free way to access the following array?
String[][] chessboard = new String[8][8];String chessPiece = chessboard[5][2];
How many elements can be stored in a two-dimensional array with dimensions 5 and 10?
50
It is possible to create an array with more than two dimensions.
True
A two-dimensional array is really a one-dimensional array of one-dimensional arrays.
True
The maximum indexes of a two-dimensional array with 6 rows and 10 columns are 5 and 9, respectively.
True
A two-dimensional array is suitable for storing tabular data
True
A one-dimensional array has only one element type, but a multidimensional array can hold several types of elements.
False
Which method signature could NOT represent an overloaded version of the following method?
public int max(int x, int y)
{
return (x > y) ? x : y;
}max(int, int)
Method overloading is helpful in which of the following situations?
When two methods perform a similar task on different types of data.
The println method in the Java API is overloaded.
True
Constructors cannot be overloaded.
False
The return type of a method is not part of the method signature.
True