Java Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

True

Each byte is assigned a unique number known as an address.

True

If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

True

Logical errors are mistakes that cause the program to produce erroneous results.

True

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

True

Programming style includes techniques for consistently putting spaces and indentation in a program to help create visual cues.

True

The Java API provides a class named Math that contains numerous methods which are useful for performing complex mathematical operations.

True

The do-while loop must be terminated with a semicolon.

True

In Java, when a character is stored in memory, it is actually the ________ that is stored.

Unicode number

In a general sense, a method is ________.

a collection of statements that perform a specific task

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

a literal

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

RAM is usually ________.

a volatile type of memory, used for temporary storage

In all but very rare cases, loops must contain, within themselves ________.

a way to terminate

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

((x > 500 && x < 650) || (y != 1000))

Which of the following is not a valid Java comment?

*/ Comment two /*

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;

40

What is the result of the following expression? 17 % 3 * 2 - 12 + 15

7

When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same name will be created.

: True

A Java program will not compile unless it contains the correct line numbers.

False

All it takes for an AND expression to be true is for one of the subexpressions to be true.

False

Colons are used to indicate the end of a Java statement.

False

In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.

False

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

False

Programs never need more than one path of execution.

False

The while loop is always the best choice in situations where the exact number of iterations is known.

False

When testing for character values, the switch statement does not test for the case of the character

False

When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

False

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

________ refers to the physical components that a computer is made of.

Hardware

________ operators are used to determine whether a specific relationship exists between two values.

Relational

The boolean expression in an if statement must evaluate to ________.

true or false

A ________ type of method performs a task and then terminates.

void

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

Values that are sent into a method are called ________.

arguments

Methods are commonly used to ________.

break a program down into small manageable pieces

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

count-controlled

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

x = 37, y = 5

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

flag

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

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

showProduct(3.3, 55);

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

single quotes, double quotes

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

str1.equalsIgnoreCase(str2)

Variables are ________.

symbolic names made up by the programmer that represent memory locations

Which of the following is the method you can use to determine whether a file exists?

the File class's exists method

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; }

this is an infinite loop

Software refers to ________.

programs

A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items to be processed.

sentinel

Which of the following is the not equal operator?

!=

A Java source file must be saved with the extension ________

.java

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = 0.05; else discountRate = 0.04; else if (purchase > 750) if (cust == 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0;

0.04

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { Case 'A': discountRate = 0.08; break; Case 'B': discountRate = 0.06; Case 'C': discountRate = 0.04; default: discountRate = 0.; }

0.06

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

1000

How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!");

12

What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales > 500) bonus = 25; else bonus =0;

25

What will be the value of x after the following code is executed? int x, y = 4, z = 6; x = (y++) * (++z);

28

What will be the value of pay after the following statements are executed? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) *payRate * 1.5;

475.00

To create a method, you must write its ________.

Definition

Which of the following would contain the translated Java byte code for a program named Demo?

Demo.class

What will be displayed after the following statements are executed? int ans = 10; int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans);

The code contains an error and will not compile.

You must have a return statement in a value-returning method.

True

A file must always be opened before using it and closed when the program is finished using it.

True

A procedure is a set of programming language statements that, together, perform a specific task.

True

A solid-state drive has no moving parts and operates faster than a traditional disk drive

True

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

True

When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.

True

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

actually a reference to the object that is passed

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x = 0, y = 50

A method

may have zero or more parameters

An item that separates other items is known as a ________.

delimiter

In a @return tag statement the description ________.

describes the return value

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

do-while

Which of the following statements is invalid?

double r = 2.9X106;

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

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

Validating the results of a program is important to ________.

make sure the program solves the original problem

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

parentheses

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

return type

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

sentinel

In the following Java statement, what value is stored in the variable name? String name = "John Doe";

the memory address where "John Doe" is located

A parameter variable's scope is ________.

the method in which the parameter is declared

When you pass an argument to a method you should be sure that the argument's type is compatible with ________.

the parameter variable's data type

In an if-else statement, if the boolean expression is false then ________

the statement or block following the else is executed

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext()) { ... }


Kaugnay na mga set ng pag-aaral

TKAM Part 2 Discussion Questions

View Set

A03 Practice Quiz for Alteryx Interactive Lessons (53 Questions)

View Set

Microsoft Excel and Access 1.07, 1.08, and 1.09

View Set

ATI Fundamentals large file study ****

View Set

Biology 106 Chapter 20: Genes Within Population

View Set

Chapter 21- The Immune System Part 1

View Set