IT practice

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

A sorting algorithm is used to locate a specific item in a larger collection of data.

F

An array can hold multiple values of several different types of data simultaneously.

F

If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

F

When an array is passed to a method ________.

All of these are true

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

T

When working with the String and StringBuilder classes' getChars method, the character at the start position is included in the substring but the character at the end position is not included.

T

You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.

T

An object's ________ is simply the data that is stored in the object's fields at any given moment.

state

What will be the results after the following code is executed? int[] array1 = new int[25];... // Code that will put values in array1int value = array1[0];for (int a = 1; a < array1.length; a++){if (array1[a] < value)value = array1[a];}

value contains the lowest value in array1

For the following code, which statement is not true? public class Circle{private double radius;public double x;private double y;}

The y field is available to code written outside the Circle class.

Assume that the following method header is for a method in class A.public void displayValue(int value)Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7;displayValue(x);

Select all that apply. Local variables ________.

lose the values stored in them between calls to the method in which the variable is declared

Java does not limit the number of dimensions an array may have.

T

Methods are commonly used to break a problem into small manageable pieces.

T

Most of the String comparison methods are case sensitive.

T

Once an array is created, its size cannot be changed.

T

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

T

StringBuilder objects are not immutable.

T

The String class's isBlank method returns true if the calling string's length is 0, or it contains only whitespace characters.

T

Which type of method performs a task and sends a value back to the code that called it?

value-returning

To determine if two arrays are equal you must compare each of the elements of the two arrays.

T

Which of the following statements will print the maximum value an int variable may have?

System.out.println(Integer.MAX_VALUE);

A class is not an object. It is a description of an object.

T

A class's static methods do not operate on the fields that belong to any instance of the class.

T

A constructor is a method that is automatically called when an object is created.

T

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 method.

T

A parameter variable's scope is the method in which the parameter is declared.

T

A value-returning method can return a reference to a non-primitive type.

T

A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables.

T

An access specifier indicates how a class may be accessed.

T

An enumerated data type is actually a special type of class.

T

An instance of a class does not have to exist in order for values to be stored in a class's static fields.

T

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.

T

Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.

T

Constants, variables, and the values of expressions may be passed as arguments to a method.

T

Declaring an array reference variable does not create an array.

T

If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.

T

If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());

T

Instance methods do not have the keyword static in their headers.

T

The String class's isEmpty method returns true if the length of the calling string is 0.

T

What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30};int value = 0;for (int i = 1; i < numbers.length; i++)value += numbers[i];

The value variable will contain the sum of all the values in the numbers array.

What does the following UML diagram entry mean? + setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

When a method's return type is a class, what is actually returned to the calling program?

a reference to an object of that class

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

The following statement is an example of ________.import java.util.*;

a wildcard import statement

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

int x = Integer.parseInt(str);

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

the program will terminate

What would be the result after the following code is executed?int[] x = {23, 55, 83, 19};int[] y = {36, 78, 12, 24};x = y;y = x;

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

When you make a copy of the aggregate object and of the objects that it references, ________.

you are performing a deep copy

The no-arg constructor for a StringBuilder object gives the object enough storage space to hold ________ characters.

16

What will be returned from the following method? public static double methodA(){double a = 8.5 + 9.5;return a;}

18.0

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

What is the value of scores[2][3] in the following array?int[][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80},{98, 95, 92, 94}, {91, 84, 88, 96} };

94

When writing documentation comments for a method, you can provide a description of each parameter by using a ________.

@param tag

What will be printed after the following code is executed? String str = "abc456";int m = 0;while ( m < 6 ){if (Character.isLetter(str.charAt(m)))System.out.print(Character.toUpperCase(str.charAt(m)));m++;}

ABC

You can declare an enumerated data type inside a method.

F

A class specifies the ________ and ________ that a particular type of object has.

fields, methods

It is common practice to use a ________ variable as a size declarator.

final

Which of the following is a valid declaration for a ragged array with five rows but no columns?

int[][] ragged = new int[5][];

When the this variable is used to call a constructor ________.

it must be the first statement in the constructor making the call

A method ________.

may have zero or more parameters

A reference variable stores a(n) ________. Correct!

memory address

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

method

A ________ is a part of a method that contains a collection of statements that are performed when the method is executed.

method body

If you have defined a class, SavingsAccount, with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

numAccounts = SavingsAccount.numberOfAccounts;

When you work with a ________, you are using a storage location that holds a piece of data.

primitive variable

All fields in an immutable class should be declared ________.

private and final

This String class method returns a string that contains the contents of the calling String object repeated a specified number of times.

repeat

What will be the result after the following code executes?double a = 2.0, b = 2.0, result;result = Math.pow(a, b) + 1;

result will be assigned 5.

Which of the following is not a part of a method call?

return type

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

semicolon

Which of the following is not part of a method header?

semicolon

You can use the ________ method to replace an item at a specific location in an ArrayList. Correct!

set

Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the ________ statement.

str[0].toUpperCase();

The process of breaking a problem down into smaller pieces is sometimes called ________.

the divide and conquer method

When a reference variable is passed as an argument to a method ________.

the method has access to the object that the variable references

To indicate the data type of a variable in a UML diagram, you enter ________.

the variable name followed by a colon and the data type

The only limitation that static methods have is ________.

they cannot refer to nonstatic members of the class

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by ________.

using the private access specifier on the class fields

A ________ type of method performs a task and then terminates

void

The whole-part relationship created by object aggregation is more often called a(n) ________ relationship.

"has a"

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

+

Which symbol indicates that a member is private a UML diagram?

-

Java automatically stores a ________ value in all uninitialized static member variables.

0

Subscripting always starts with ________.

0

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

Given the following declaration:enum Tree ( OAK, MAPLE, PINE )What is the ordinal value of the MAPLE enum constant?

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 position after the following code is executed?int position;String str = "The cow jumped over the moon.";position = str.lastIndexOf("ov", 14);

14

What would be the result of executing the following code?int[] x = {0, 1, 2, 3, 4, 5};

An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.

Local variables can be initialized with ________.

Any of the above (constants, parameter values, the results of an arithmetic operation)

In Java it is possible to write a method that will return ________.

Any of these

A value-returning method must specify ________ as its return type in the method header.

Any valid data type

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method C.

________ refers to combining data and code into a single object.

Encapsulation

A method that gets a value from a class's field but does not change it is known as a mutator method.

F

Instance methods should be declared static.

F

What does specify in the following statement?ArrayList nameList = new ArrayList();

It creates an instance of an array of ten long values.

Which of the following is not true about static methods?

It is necessary for an instance of the class to be created to execute the method.

Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10;long[] array1 = new long[ARRAY_SIZE];

It will allow valid subscripts in the range of 0 through 9.

Any items typed on the command line, separated by a space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

T

enum constants have a toString method.

T

What will be the result after the following code is executed? final int ARRAY_SIZE = 5;float[] x = float[ARRAY_SIZE];for (i = 1; i <= ARRAY_SIZE; i++){x[i] = 10.0;}

The code contains a syntax error and will not compile.

What will be displayed after the following code is executed?StringBuilder strb = new StringBuilder(12);strb.append("The cow ");strb.append("jumped over the ");strb.append("moon.");System.out.println(strb);

The cow jumped over the moon.

Given the following, which of the statements below is not true? str.insert(8, 32);

The insert will start at position 32.

Given the following two-dimensional array declaration, which statement is true?int[][] numbers = new int[6][9];

The numbers array has 6 rows and 9 columns.

For the following code, which statement is not true? public class Sphere{private double radius;public double x;private double y;private double z;}

The z field is available to code written outside the Sphere class.

Which of the following is not true about static methods?

They are called from an instance of the class.

What would be the result after the following code is executed? final int SIZE = 25;int[] array1 = new int[SIZE];... // Code that will put values in array1int value = 0;for (int a = 0; a <= array1.length; a++){value += array1[a];}

This code would cause the program to crash.

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

This is a public method named add that accepts and returns references to objects in the Stock class.

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

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

Each of the numeric wrapper classes has a static ________ method that converts a number to a string.

ToString

What will be displayed after the following code is executed?String str = "RSTUVWXYZ";System.out.println(str.charAt(5));

W

What will the following code display?String str = "xyz".repeat(3).replace("yz", "ab").toUpperCase();System.out.println(str);

XABXABXAB

What will the following code display?String str = "a".repeat(3).replace("a", "z").toUpperCase();System.out.println(str);

ZZZ

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5])a = 5; else a = 8;

a = 5

When a method tests an argument and returns a true or false value, it should return ________.

a boolean value

You cannot use the fully-qualified name of an enum constant for ________.

a case expression

In a general sense, a method is ________.

a collection of statements that perform a specific task

If you attempt to use a local variable before it has been given a value, ________.

a compiler error will occur

A ragged array is ________.

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

In the following code, Math.Pow(a, b) is an example of ________.double a = 2.0, b = 2.0, result;result = Math.pow(a, b) + 1;

a value-returning method

In the following code, System.out.println(num) is an example of ________.double num = 5.4;System.out.println(num);num = 0.0;

a void method

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList?

add

A static field is created by placing the key word static ________.

after the access specifier and before the field's data type

The StringBuilder class's insert method allows you to insert a(n) ________ into the calling object's string.

all of these

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

an explicit import statement

All @param tags in a method's documentation must ________.

appear after the general description of the method

Values stored in local variables ________.

are lost between calls to the method in which they are declared

What is the value of str after the following code has been executed?String str;String sourceStr = "Hey diddle, diddle, the catand the fiddle";str = sourceStr.substring(12,17);

diddle

Given the following method header, which of these method calls is incorrect?public void displayValue(double x, int y);

displayValue(a, b); // where a is a short and b is a long

What will be returned from the following method?public static int methodA(){double a = 8.5 + 9.5;return a;}

error

If str is declared as: String str = "ABCDEFGHI";What will be returned from the following statement?Character.toLowerCase(str.charAt(5))

f

It is common practice in object-oriented programming to make all of a class's ________.

fields private

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};

for (int i = 0; i < names.length; i++)System.out.println(names[i].length());

If numbers are a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array?

for (int row = 0; row < numbers.length; row++){for (int col = 0; col < numbers[row].length; col++)total += numbers[row][col];}

The JVM periodically performs the ________ process to remove unreferenced objects from memory.

garbage collection

A constructor ________.

has the same name as the class

Select all that apply. Any method that calls a method with a throws clause in its header must ________.

have the same throws clause, handle the potential exception

A class whose internal state cannot be changed is known as a(n) ________ class.

immutable

Is the following class mutable or immutable? public final class Status { private final String code; public Status(String c) { code = c; } public String getCode() { return code; } }

immutable

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

in order to avoid having stale data

A class that is defined inside another class is called a(n) ________.

inner class

Another term for an object of a class is a(n) ________.

instance

When an object is created, the attributes associated with the object are called ________.

instance fields

Methods that operate on an object's fields are called ________.

instance methods

Select all that apply. Which of the following types of values can be passed to a method that has an int parameter variable?

int

A deep copy of an object ________.

is an operation that copies an aggregate object and all the objects that it references

A search algorithm ________.

is used to locate a specific item in a collection of data

What does the following statement do?double[] array1 = new double[10];

it does all of these

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

The ________ package is automatically imported into all Java programs.

java.lang

You should always document a method by writing comments that appear ________.

just before the method's definition

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

long[]

A class that provides mutators to change the values of the class's fields is known as a(n) ________ class.

mutable

Is the following class mutable or immutable? public final class Status{private String code; public Status(String c) { code = c; } public void set Code(String c) { code = c; } public String getCode() { return code; } }

mutable

Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

nonletter

If numbers are a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

Most of the programming languages used today are ________.

object-oriented

You cannot use the == operator to compare the contents of ________.

objects

When a field is declared static there will be ________.

only one copy of the field in memory

The lifetime of a method's local variable is ________.

only while the method is executing

A group of related classes is called a(n) ________.

package

A special variable that holds a value being passed into a method is called a(n) ________.

parameter

In the header, the method name is always followed by ________.

parentheses

A constructor is a method that ________.

performs initialization or setup operations

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passMyArray(int[][])

What will be displayed after the following statements are executed?String str = "red$green&blue#orange";String[] tokens = str.split("[$&#]");for (String s : tokens)System.out.print(s + " ");

red green blue orange

The ________ method removes an item from an ArrayList at a specific index.

remove

Given the following method, which of these method calls is valid?public static void showProduct (int num1, double num2){int product;product = num1 * (int)num2;System.out.println("The product is " + product);}

showProduct(10, 4.5);

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

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

A(n) ________ is used as an index to pinpoint a specific element within an array.

subscript

The term ________ commonly is used to refer to a string that is part of another string.

substring

Given the following method header, what will be returned from the method?

the address of an object of the Rectangle class

The header of a value-returning method must specify ________.

the data type of the return value

When an individual element of an array is passed to a method, ________.

the method does not have access to the original array

A parameter variable's scope is ________.

the method in which the parameter is declared

A UML diagram does not contain ________.

the object names

When an object is passed as an argument to a method, what is passed into the method's parameter variable?

the object's memory address

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

they have different parameter lists

A series of words or other items of data, separated by spaces or other characters, is known as a ________.

token

The process of breaking a string down into tokens is known as ________.

tokenizing

The ________ character appears at the end (the right side) of a string, after the non-space characters.

trailing whitespace

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.

trim

What will be the value of matches after the following code is executed?boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1, productCodes[1], 2, 3);

true

The process of converting a wrapper class object to a primitive type is known as ________.

unboxing

The sequential search algorithm ________.

uses a loop to sequentially step through an array, starting with the first element

The binary search algorithm ________.

will cut the portion of the array being searched in half each time it fails to locate the search value

A partially filled array is normally used ________.

with an accompanying integer value that holds the number of items stored in the array

What is the term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables?

wrapper class

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

To compare two objects in a class, ________.

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

An object can store data.

T

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 double finalOrderTotal(){ return orderAmount - orderAmount * orderDiscount;}}public class CustomerOrder{public static void main(String[] args){ Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(orderNumber, orderAmt, orderDisc); double finalAmount = order.finalOrderTotal(); System.out.printf("Final order amount = $%,.2f\n",finalAmount);}}

522.00

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 = 20;for(int i = 0; i < SUB; i++){x[i] = y;y += 5;}

60

In the following code, how many times will the for loop execute?String str = "1,2,3,4,5,6,7,8,9");String[] tokens = str.split(",");for (String s : tokens) System.out.println(s);

9

What are the tokens in the following statement?StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);

9, 14, 2018, -

Autoboxing is ________.

Java's process of automatically "boxing up" a value inside an object

Which of the following import statements is required to use the Character wrapper class?

No import statement is required

Select all that apply. Which of the following are benefits of using methods in programming?

Problems are solved more easily.

Select all that apply. Which of the following are classes from the Java API?

Random

Instance methods do not have the ________ keyword in their headers.

Static

Static methods can only operate on ________ fields.

Static

Java allows you to create objects of the ________ class in the same way you would create primitive variables.

String

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

String str = "Hello, World";

A class's responsibilities include ________.

both of these

After the header, the body of the method appears inside a set of ________.

braces, { }

Methods are commonly used to ________.

break a program down into small manageable pieces

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

class

You can concatenate String objects by using the ________.

concat method or the + operator

This String class method returns true if the calling String object contains a specified substring.

contains

When an argument value is passed to a method, the receiving parameter variable is ________.

declared in the method header inside the parentheses

To create a method, you must write its ________.

definition

Given the following declaration:enum Tree ( OAK, MAPLE, PINE )What is the fully-qualified name of the PINE enum constant?

Tree.PINE

The term used for the character that separates tokens is ________.

delimiter

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

T

If a class has mutator methods, it is probably an immutable class.

F

If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned.

F

If an immutable class has a mutable object as a field, it is permissible for a method in the immutable class to return a reference to the mutable field.

F

In the method header the static method modifier means the method is available to code outside the class.

F

In the method header, the method modifier public means that the method belongs to the class, not a specific object.

F

Java limits the number of dimensions that an array can have to 15.

F

Only constants and variables may be passed as arguments to methods.

F

The Double.parseDouble method converts a double to a string.

F

The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.

F

The key word this is the name of a reference variable that is available to all static methods.

F

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

F

The term "default constructor" is applied to the first constructor written by the author of the class.

F

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

F

When an object, such as a String, is passed as an argument it is ________.

actually a reference to the object that is passed

The ________ method is used to insert an item into an ArrayList.

add

Values that are sent into a method are called ________.

arguments

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

array bounds checking

A single copy of a class's static field is shared by all instances of the class.

T

A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

T

If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.

T

If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

T

The String class's regionMatches method performs a case-insensitive comparison.

T

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

T

The expression in a return statement can be any expression that has a value.

T

The java.lang package is automatically imported into all Java programs.

T

The key word this is the name of a reference variable that an object can use to refer to itself.

T

Trying to extract more tokens than exist from a StringTokenizer object will cause an error.

T

Two general categories of methods are void methods and value-returning methods.

T

When an array of objects is declared but not initialized, the array values are set to null.

T

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

T

When an object reference is passed to a method, the method may change the values in the object.

T


Conjuntos de estudio relacionados

Chapter 5: Field Underwriting Procedures

View Set

Porth's Chapter 25: Structure and Function of the Cardiovascular System

View Set

Tinker v Des Moines Independent Community School District

View Set

Unit 3 Tissue Repair and Application Assignment

View Set

Smartbook Chapter 15: Eukaryotic Gene Regulation

View Set

NPSP (Exam Category: Nonprofit Cloud Solution Design (Weighting = 24% of the exam)

View Set