What invokes a scheduled Timer?

What invokes a scheduled Timer? 


a. AbstractTask
b. ScheduledTask
c. Task
d. TimerTask


Answer: d. TimerTask

What does the splash screen provide time for Android to do?

What does the splash screen provide time for Android to do? 


a. bootstrap the phone driver
b. download updates
c. initialize resources for your app
d. stream data from Google


Answer: c. initialize resources for your app

What is printed to the console after the code that follows is executed?

What is printed to the console after the code that follows is executed?

int[][] types = new int[4][];
for (int i = 0; i < types.length; i++)
{
types[i] = new int[i+1];
}
System.out.println(types[1].length);

a. "3"
b. code doesn't compile
c. "1"
d. "4"
e. "2"


Answer: e. "2"

What happens when the code that follows is executed?

What happens when the code that follows is executed?

int[] nums = new int[4];
for (int i = 0; i <= nums.length; i++)
{
nums[i] = i;
}
System.out.println(nums[2]);

a. It prints "3" to the console.
b. It prints "2" to the console.
c. It prints "1" to the console.
d. It throws an ArrayIndexOutOfBoundsException


Answer: d. It throws an ArrayIndexOutOfBoundsException

What is the length of the bestTimes array?

double[] times = {3.56, 3.9, 2.6, 4.5, 2.4, 5.2};
double[] bestTimes = new double[4];
Arrays.sort(times);
bestTimes = Arrays.copyOfRange(times, 1, 4);

What is the length of the bestTimes array?


a. 4
b. 3
c. 6
d. 5


Answer: a. 4

An enhanced for loop can only be used

An enhanced for loop can only be used


a. to work with one-dimensional arrays
b. to work with all the elements of an array
c. to work with jagged arrays
d. to work with arrays that contain integers


Answer: b. to work with all the elements of an array

Which of the following is not a reason to create a package?

Which of the following is not a reason to create a package?


a. To group related classes
b. To make finding classes easier
c. To make it easy to reuse classes
d. To prevent other developers from using the class


Answer: d. To prevent other developers from using the class

Which of the following is a valid Javadoc comment?

Which of the following is a valid Javadoc comment?


a. // Calculates the balance due //
b. / Calculates the balance due */
c. /* Calculates the balance due /
d. / Calculates the balance due /


Answer: c. /* Calculates the balance due /

Which of the following is a benefit of using Javadoc comments?

Which of the following is a benefit of using Javadoc comments?


a. They show other programmers how to code a class.
b. They make it easy for other programmers to learn about your class.
c. They allow other programmers to view the source code for your class.
d. They make your classes easier to debug.


Answer: b. They make it easy for other programmers to learn about your class.

Where must you code the Javadoc comment for a method?

Where must you code the Javadoc comment for a method?


a. Immediately before the method
b. After any statements in the method
c. Before any statements in the method
d. Anywhere within the method


Answer: a. Immediately before the method

To include a class in a package, you

To include a class in a package, you


a. code an import statement as the first statement of the class
b. code a package statement as the first statement in the class file
c. code the name of the package in the class declaration
d. code a package statement as the last statement in the class file


Answer: b. code a package statement as the first statement in the class file

A subclass inherits

A subclass inherits


a. protected data only
b. public, private, and protected data
c. public and private data
d. public and protected data


Answer: d. public and protected data

A class in the Java API

A class in the Java API


a. can be both a superclass and a subclass
b. can be inherited only by other classes in the Java API
c. can have only one subclass
d. can be inherited only by user-defined classes


Answer: a. can be both a superclass and a subclass

A static initialization block

A static initialization block


a. is used to initialize a static variable that can't be initialized in the declaration
b. is executed when a static method of the class is called
c. is executed when an instance of the class is created
d. all of the above
e. a and b only


Answer: d. all of the above

You can create a ____ partition to hold files that are created temporarily, such as files used for printing documents (spool files) and files used to record monitoring and administration data, often called log files.

You can create a ____ partition to hold files that are created temporarily, such as files used for printing documents (spool files) and files used to record monitoring and administration data, often called log files.


/tmp
/usr
/var
/aux


Answer: /var

The goal of testing is to

The goal of testing is to


a. make sure the application works with invalid data
b. fix all errors in the application
c. make sure the application works with valid data
d. find all errors in the application


Answer: d. find all errors in the application

What happens in the method that follows when s is "two"?

What happens in the method that follows when s is "two"?

public double parseInterval(String s)
{
double interval = 0.0;
try
{
interval = Double.parseDouble(s);
}
catch(NumberFormatException e)
{
}
return interval;
}

a. no value is returned since the catch block doesn't return a value
b. a compile-time error occurs since the catch block isn't properly coded
c. 0.0 is returned
d. 2.0 is returned


Answer: 0.0 is returned

What is the order of method calls?

What is the order of method calls?


a. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor
b. java.util.Scanner.throwFor calls java.util.Scanner.next calls java.util.Scanner.nextDouble calls FutureValueApp.main
c. you can't tell from the information given


Answer: FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor

What is this output called?

What is this output called?


a. a method log
b. a stack trace
c. an exception handler
d. an exception hierarchy


Answer: a stack trace

Output example:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)

Consider the code that follows. What does it do?

Consider the code that follows. What does it do?

String value = "2";
boolean tryAgain = true;
while (tryAgain == true)
{
try
{
int num = Integer.parseInt(value);
tryAgain = false;
}
System.out.println("Valid integer");
catch(NumberFormatException nfe)
{
System.out.println("Invalid integer");
System.out.print("Enter an integer");
value = sc.next
}
}

a. It prints "Invalid integer" to the console.
b. The code compiles but causes a runtime error.
c. The code doesn't compile.
d. It prints "Valid integer" to the console.


Answer: The code doesn't compile.

Output example:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)

If the user enters 118 at the console prompt, what is the third line of the resulting console display?

import java.util.Scanner;
import java.text.NumberFormat;

public class WeightConverter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String prompt = "Enter weight in lbs: ";
boolean isValid = false;
double weightInPounds = 0.0;
while (isValid == false)
{
weightInPounds = getDouble(sc, prompt);
if (weightInPounds > 0)
isValid = true;
else
System.out.println("Weight must be greater than 0.");
}
double weightInKilos = weightInPounds / 2.2;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
String message = weightInPounds + " lbs\nequals\n"
+ nf.format(weightInKilos) + " kgs\n";
System.out.print(message);
}

public static double getDouble(Scanner sc, String prompt)
{
double d = 0.0;
boolean isValid = false;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println
("Error! Invalid decimal value. Try again.");
}
sc.nextLine();
}
return d;
}
}



If the user enters 118 at the console prompt, what is the third line of the resulting console display?


a. 53 kgs
b. 54 kgs
c. 53.64 kgs
d. 53.6363 kgs


Answer: 53.64 kgs

If the user enters -1 at the first console prompt, what does the code do?

import java.util.Scanner;
import java.text.NumberFormat;

public class WeightConverter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String prompt = "Enter weight in lbs: ";
boolean isValid = false;
double weightInPounds = 0.0;
while (isValid == false)
{
weightInPounds = getDouble(sc, prompt);
if (weightInPounds > 0)
isValid = true;
else
System.out.println("Weight must be greater than 0.");
}
double weightInKilos = weightInPounds / 2.2;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
String message = weightInPounds + " lbs\nequals\n"
+ nf.format(weightInKilos) + " kgs\n";
System.out.print(message);
}

public static double getDouble(Scanner sc, String prompt)
{
double d = 0.0;
boolean isValid = false;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println
("Error! Invalid decimal value. Try again.");
}
sc.nextLine();
}
return d;
}
}

If the user enters -1 at the first console prompt, what does the code do?


a. figures the weight in kilograms
b. displays an error message from the main method
c. catches an exception
d. displays an error message from the getDouble method


Answer: b. displays an error message from the main method

If the user enters "two hundred" at the console prompt, what does the code do?

import java.util.Scanner;
import java.text.NumberFormat;

public class WeightConverter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String prompt = "Enter weight in lbs: ";
boolean isValid = false;
double weightInPounds = 0.0;
while (isValid == false)
{
weightInPounds = getDouble(sc, prompt);
if (weightInPounds > 0)
isValid = true;
else
System.out.println("Weight must be greater than 0.");
}
double weightInKilos = weightInPounds / 2.2;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
String message = weightInPounds + " lbs\nequals\n"
+ nf.format(weightInKilos) + " kgs\n";
System.out.print(message);
}

public static double getDouble(Scanner sc, String prompt)
{
double d = 0.0;
boolean isValid = false;
while (isValid == false)
{
System.out.print(prompt);
if (sc.hasNextDouble())
{
d = sc.nextDouble();
isValid = true;
}
else
{
System.out.println
("Error! Invalid decimal value. Try again.");
}
sc.nextLine();
}
return d;
}
}

If the user enters "two hundred" at the console prompt, what does the code do?


a. figures the weight in kilograms
b. displays an error message from the main method
c. displays an error message from the getDouble method
d. throws an InputMismatchException


Answer: c. displays an error message from the getDouble method

When is the code within a catch block executed?

When is the code within a catch block executed?


a. When the exception specified in the catch block is thrown in the try block
b. When a runtime error occurs
c. When the try block finishes executing
d. When the code in the try block doesn't compile


Answer: a. When the exception specified in the catch block is thrown in the try block

What is the main reason for using a generic data validation method?

What is the main reason for using a generic data validation method?


a. It runs faster than the validation code in the main method.
b. It saves you from writing variations of the same code again and again to check multiple data entries.
c. It prevents NumberFormatExceptions from being thrown.
d. None of the above.


Answer: b. It saves you from writing variations of the same code again and again to check multiple data entries.

To handle an exception using the try statement, you must

To handle an exception using the try statement, you must


a. code a try block around the statement that may throw the exceptions
b. code a finally block that contains the statements that will be executed at the end of the try statement
c. code a catch block that contains the statements that you want to be executed when the exception occurs
d. all of the above
e. a and c only


Answer: a and c only

To determine the cause of an unhandled exception, you can

To determine the cause of an unhandled exception, you can


a. use the name of the exception class that's displayed
b. use the error message that's displayed
c. use the information in the stack trace
d. all of the above


Answer: all of the above

In Java, exceptions are

In Java, exceptions are


a. statements
b. classes
c. compile-time errors
d. objects


Answer: objects

What is the order of method calls?

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)


What is the order of method calls?


a. java.util.Scanner.throwFor calls java.util.Scanner.next calls java.util.Scanner.nextDouble calls FutureValueApp.main
b. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor
c. you can't tell from the information given


Answer: b. FutureValueApp.main calls java.util.Scanner.nextDouble calls java.util.Scanner.next calls java.util.Scanner.throwFor

Which statement would you look at to find the source of the problem?

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)

Which statement would you look at to find the source of the problem?


a. line 818 in the Scanner class
b. line 2324 in the Scanner class
c. line 17 in the FutureValueApp class
d. line 1420 in the Scanner class


Answer: c. line 17 in the FutureValueApp class

What caused the exception to occur?

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)


What caused the exception to occur?


a. You can't tell from the information given.
b. The user didn't enter the type of data the program was expecting.
c. The program couldn't format the double value that the user entered.


Answer: b. The user didn't enter the type of data the program was expecting.

Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:818) at java.util.Scanner.next(Scanner.java:1420) at java.util.Scanner.nextDouble(Scanner.java:2324) at FutureValueApp.main(FutureValueApp.java:17) What is this output called?

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
What is this output called?


a. a method log
b. a stack trace
c. an exception handler
d. an exception hierarchy


Answer: b. a stack trace

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because

You should validate user entries rather than catch and handle exceptions caused by invalid entries whenever possible because


a. all of the above
b. data validation code should only be used for situations that are truly exceptional
c. your code will run faster
d. you can more accurately determine the cause of an invalid entry


Answer: c. your code will run faster

To handle an exception using the try statement, you must

To handle an exception using the try statement, you must


a. code a try block around the statement that may throw the exceptions
b. code a finally block that contains the statements that will be executed at the end of the try statement
c. code a catch block that contains the statements that you want to be executed when the exception occurs
d. all of the above
e. a and c only


Answer: e. a and c only

To determine the cause of an unhandled exception, you can

To determine the cause of an unhandled exception, you can


a. use the name of the exception class that's displayed
b. use the error message that's displayed
c. use the information in the stack trace
d. all of the above


Answer: d. all of the above

The has methods of the Scanner class let you

The has methods of the Scanner class let you


a. check if the user has entered data at the console
b. check if the data entered at the console can be converted to a specific data type
c. retrieve and discard data that isn't required by the application
d. all of the above
e. a and b only



Answer: e. a and b only

Which of the following correctly completes the statement below to instantiate a SharedPreferences object? SharedPreferences sharedPref =

Which of the following correctly completes the statement below to instantiate a SharedPreferences object?
SharedPreferences sharedPref =


a. PreferenceManager.getDefaultSharedPreferences(this);
b. SharedPreferences.PreferenceManager.getDefault(this);
c. SharedPreferences.getDefaultPreferenceManager(this);
d. PreferenceManager.SharedPreferences.getDefault(this);


Answer: a. PreferenceManager.getDefaultSharedPreferences(this);

What's the first step when writing persistent data using a SharedPreferences file?

What's the first step when writing persistent data using a SharedPreferences file?


a. Create a SharedPreferences.Editor object
b. Obtain an instance of the SharedPreferences file
c. Assign values into SharedPreferences objects
d. Save the values to the preferences file


Answer: b. Obtain an instance of the SharedPreferences file

What does the abbreviation SQL stand for?

What does the abbreviation SQL stand for?


a. Structured Quorum List
b. Simple Quorum Language
c. Simple Query List
d. Structured Query Language


Answer: d. Structured Query Language

Before an app attempts to connect to a network connection, what action should be taken?

Before an app attempts to connect to a network connection, what action should be taken?


a. The app should scan the quality of the network.
b. No action needs to be taken.
c. The app should see if an Internet connection is available.
d. The app should open a network's web browser.


Answer: c. The app should see if an Internet connection is available.

Which ListView control provides a two-level list?

Which ListView control provides a two-level list?


a. DoubleListView
b. MultiListView
c. ExpandableListView
d. AdvancedListView


Answer: c. ExpandableListView

Where is the strings.xml file located?

Where is the strings.xml file located?




a. res/drawable-mdpi folder
b. res/layout folder
c. res/values folder
d. res/drawable-hdpi folder


Answer: c. res/values folder

What is the generic layout to a simple list?

What is the generic layout to a simple list?


a. simple_list_item_multiple_choice
b. simple_list_item_2
c. simple_list_item_1
d. simple_list_item_checked


Answer: c. simple_list_item_1

What is the generic layout that displays checkboxes?

What is the generic layout that displays checkboxes?


a. list_item_checked
b. boxed_list_item
c. simple_list_item_checked
d. checked_list_item


Answer: c. simple_list_item_checked

What does the acronym URL stand for?

What does the acronym URL stand for?


a. Uniform Resource Locator
b. Usual Random Lesson
c. Universal Redirection Locale
d. Utility Rendering Logo


Answer: a. Uniform Resource Locator