Comp sci

¡Supera tus tareas y exámenes ahora con Quizwiz!

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; postion = str.lastIndexOf("ov",14);

-1

What are the tokens in the following code?: String str = "123-456-7890"; String tokens = str.split("-");

123,456,7890

What will be the value of x[8] after the following code is executed? Final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++){ x[i] = y; y+=10; }

180

The _______ method is used to insert an item into an arraylist

Add

Which of the following problems can be solved recursively A)greatest common denominator B) Towers of Hanoi C)Binary Search D) All of the above

All of the above

The following statement is an example of: import java.util.Scanner;

An explicit import statement

The ______ is at least one case in which a problem can be solved without recursion.

Base Case

You should not define a class that is dependent on the values of other class fields

In order to avoid having stale data

____ occurs when method A calls Method B which in turn calls method A

Indirect Recursion

In a catch statement, what does the following code do System.out.println(e.getMessage());

It prints the error message for an exception.

The _____ package is automatically imported into all Java programs.

Java.lang

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

Methods

Which of the following import statements is required to use the characters wrapper class A) import java.String; B) import java.lang.Char; C) import java.Char D) No import statement is required

No import statement is required

The numeric classes' "parse" methods all throw an exception of ______ if the string being converted does not contain a convertible numeric value.

NumberFormatException

A UML diagram does not contain

The object names

If you attempt to perform an operation with a null reference variable:

The program will terminate

Which of the following is not true about static methods

They are called from an instance of the class

Two or more methods in a class may have the same name, as long as

They have different parameter lists

One or more objects may be created from a(n):

class

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

str[0].toUpperCase();

When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to _______.

the first catch clause that can handle the exception

In java there are two categories of exceptions which are ________.

unchecked and checked

To compare two objects in a class

write an equals method that will make a field by field compare of the two objects

Which symbol indicates that a member is public in a UML diagram?

+

If object1 and object2 are objects of the same class, to make object2 a copy of object1

Write a method for the class that will make a field by field copy of object1 data members into object2 data members

If a method does not handle a possible checked exception, what must the method have?

a throws clause in its header

A ragged array is ______

a two-dimensional array where the rows have different numbers of columns

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

If a subclass constructor does not explicitly call a superclass constructor:

java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes.

To return an array of long values from a method, which return type should be used for the method?

long[]

which of the following is the operator used to determine whether an object is an instance of a particular class?

instanceOf

Given the following code that uses recursion to find the factorial of a number, how many times will the else clause be executed if n = 5? private static int factorial(int n){ if(n==0){ return 1; } else{ return n * factorial(n-1); } }

5

When recursive methods directly call themselves, it is known as _______.

Direct Recursion

Unchecked exceptions are those that inherit from the

Error class or RuntimeException class

All of the exceptions that you will handle are instances of classes that extend ______ class.

Exception

A group of related classes is called a

Package

When using the String class's trim method, a ________ cannot be trimmed.

Semicolon

Which of the following statements will create a reference, str, to the String "Hello, World"?

String str = "Hello, World";

If the following is from the method section of a UML diagram, which of the statements is true? + equals(object2:Stock) : boolean

This is a public method that accepts a Stock object as its argument and returns a boolean value

A method that calls itself is a ________ method.

recursive

What would be the results of the following code?: StringBuilder str = new StringBuilder("Little Jack Horner "); str.append("sat on the "); str.append("corner");

str would reference "Little Jack Horner sat on the corner".

the ____ key word is used to call the superclass constructor explicitly

super

To use recursion for a binary search, what is required before the search can proceed?

the array must be sorted

A method is called from the main method for the first time. It then calls itself 7 times. What is the depth of recursion

7

Classes that inherit from the Error class are for exceptions that are thrown when ______

A critical error occurs, and the application program should not try to handle them

In the following code that uses recursion to find the factorial of a number, what is the Base Case? private static int factorial(int n){ if(n == 0){ return 1; } else{ return n * factorial(n-1); } }

if(n == 0){ return 1; }

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case? public static int gcd(int x, int y){ if(x % y == 0){ return y; } else{ return gcd(y, x % y); } }

if(x % y == 0){ return y; }

In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by this symbol:

|


Conjuntos de estudio relacionados

Intro to Computer Programming Midterm Review

View Set

4x4 places and people in the city 4th nine weeks 13

View Set