ITP 120 Midterm

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

When a character is stored in memory, it is actually the ________ that is stored.

Unicode number

A Java program must have at least one of the following:

a class definition

What will be the value of x after the following statements are executed? int x = 10; for (int y = 5; y < 20; y +=5) x += y;

20

You can use the enum key word to

F Both of these

Computers can do many different jobs because they are

programmable.

________ is the term for the relationship created by object aggregation.

"Has a"

A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data.

data hiding

An item that separates other items is known as a

delimiter.

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

do-while

Variables of the boolean data type are useful for

evaluating conditions that are either true or false.

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

fields private.

A ________ is a boolean variable that signals when some condition exists in the program.

flag

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

garbage collection

Overloading is

having two or more methods with the same name but different signatures.

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?

if (temp >= 0 && temp <= 100)

Which is the key word used to import a class?

import

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.io.*;

Which of the following import statements is required in order to use the ArrayList class?

import java.util.ArrayList;

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

import java.util.StringTokenizer;

Which statement tells the compiler where to find the JOptionPane class and makes it available to your program?

import javax.swing.JOptionPane;

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

in order to avoid having stale data.

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop

infinite

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

inner class.

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

instance fields.

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);

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

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

A search algorithm

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

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

long[]

Assume you are at the operating system command line and want to use the following command to compile a program: javac MyClass.java Before entering the command you must

make sure you are in the same directory or folder where the MyClass.java file is located.

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

methods

Which of the following expressions will generate a random number in the range of 1 through 10?

myNumber = randomNumbers.nextInt(10) + 1;

Which Scanner class method reads a String?

nextLine

A constructor is a method that

performs initialization or setup operations.

The two primary methods of programming in use today are

procedural and object-oriented

A(n) ________ is used to write computer programs.

programming language

When an array is passed to a method

the method has direct access to the original array. it is passed just as any other object would be passed. a reference to the array is passed.

What is syntax?

the rules that must be followed when writing a program

A class's responsibilities include

the things a class is responsible for doing. the things a class is responsible for knowing. both of these.

To indicate the data type of a variable in a UML diagram you specify

the variable name followed by a colon and the data type.

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

you are performing a deep copy.

The ________ class is the wrapper class for the char data type.

Character

CRC stands for

Class, Responsibilities, Collaborations

Which of the following statements opens a file named MyFile.txt and allows you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

Assume the following declaration exists: enum Tree ( OAK, MAPLE, PINE ) What will the following code display? System.out.println(Tree.OAK);

OAK

Which of the following statements will create an object from the Random class?

Random myNumber = new Random();

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?

SavingsAccount.getNumberOfAccounts();

Which of the following statements correctly creates a Scanner object for keyboard input?

Scanner keyboard = new Scanner(System.in);

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

String str = Integer.toString(number);

To print "Hello, world" on the monitor, which of the following Java statements should be used?

System.out.println("Hello, world");

Which of the following statements will display the maximum value that a double can hold?

System.out.println(Double.MAX_VALUE);

What will be the result after the following code is executed?

The code contains a syntax error and will not compile.

What will be the result after the following code is executed? int [] numbers = { 50, 10, 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.

Which of the following is a value that is written into the code of a program?

a literal

A runtime error is usually the result of

a logical error.

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"

Java requires that the boolean expression being tested by an if statement be enclosed in

a set of parentheses.

RAM is usually

a volatile type of memory, used for temporary storage.

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 data type.

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.

aggregate

What is the following statement an example of? import java.util.Scanner;

an explicit import statement

Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'?

chrA != 'A'

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

class

In the ________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells.

comma separated value

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

conditional

A loop that repeats a specific number of times is known as a(n)

count-controlled.

When you write an enumerated type declaration, you

All of these

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

braces, { }

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

public static void passMyArray(int[][] myArray)

What will be displayed after the following statements are executed?

red green blue orange

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

remove

A ________ is a value that signals when the end of a list of values has been reached.

sentinel

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

set

Before entering a loop to compute a running total, the program should first

set the accumulator variable to an initial value, often

The ________ method is used to display a message dialog.

showMessageDialog

Character literals are enclosed in ________ and string literals are enclosed in ________.

single quotes, double quotes

Variables are

symbolic names made up by the programmer that represent memory locations.

The Character wrapper class provides numerous methods for

testing and converting character data.

In general, there are two types of files which are

text and binary.

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

the address of an object of the Rectangle class

In order to do a binary search on an array

the array must first be sorted.

The data contained in an object is known as

the attributes

Which of the following can you use to compare two enum data values?

the equals and compareTo methods

Which of the following methods returns a string representing all of the items stored in an ArrayList object?

toString

A series of words or other items of data, separated by spaces or other characters, are known as

tokens.

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

trim

The boolean expression in an if statement must evaluate to

true or false.

To get the name of a calling enum constant

use the toString method.

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

valueOf

A partially filled array is normally used

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

The simplest way to use the System.out.printf method is

with only a format string and no additional arguments.

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;

x = 33, y = 9


Conjuntos de estudio relacionados

TXST Marketing 3343 Natesan - Exam 4

View Set

Final exam lecture test questions

View Set