Master Java study - OG

Ace your homework & exams now with Quizwiz!

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

True

Programming Style includes spaces and indentation for visual cues

True

System.out.printf allows you to print in a variety of ways

True

Named constants are initialized with a value, and that value cannot change during execution

True - keyword CONSTANT

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

Unicode number

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

Every Java application program must have

a method named main

A computer program is

a set of instructions that allow the computer to solve a problem or perform a task

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

a set of parentheses

Which of the following is a named storage location in the computer's memory?

a variable

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 less than or equal to 500 or greater than 650, or int y not equal to 1000?

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

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 would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; if (purchase > 1000) discountRate = .05; if (purchase > 750) discountRate = .03; if (purchase > 500) discountRate = .01; else discountRate = 0;

.01

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

120

What will be the value of x after the following code is executed? int x, y = 15; x = y--;

15

What will be the value of x after the following statements are executed? int x = 75; int y = 60; if (x > y) x = x - y;

15

What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;

165

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 will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x);

45,678.26

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

7

There are __________ bits in a byte.

8

Predict the Output: int x = 0, y = 2; x = y * 4; System.out.println(x + "\n" + y + "\n");

8 2

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

8.0

What is the value of ans after the following code has been executed?

80

What does the following code display? int d = 9, e = 12; System.out.printf("%d %d\n", d, e);

9 12

Which of the following is not part of the programming process?

All of these are parts of the programming process

F (semicolons)

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

F (complied byte code comes from a source code but is different)

Compiled byte code is also called source code.

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

When two strings are compared using the String class's compareTo method, the comparison is not case sensitive.

FALSE

Both character and string literals can be assigned to a char varible

False

Class names and keywords are examples of varibles

False

Java class will not compile unless it contains the correct line numbers

False -- The compilation process focuses on the correctness of the code, syntax, and semantics, rather than the specific line numbers in the source file.

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

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

Flag

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

Hardware

What will be displayed as a result of executing the following code? int x = 6; String msg = "I am enjoying this class."; String msg1 = msg.toUpperCase(); String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strSize + "characters.");

I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 25characters.

Predict the Output: System.out.print("I am the incredible"); System.out.print("computing\nmachine"); System.out.print("\nand I will\namaze\n"); System.out.println("you.");

I am the incrediblecomputing machine and I will amaze you. note* newline character ("\n"),

Which of the following is not a rule that must be followed when naming identifiers?

Identifiers can contain spaces.

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 && number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); }

Impossible - the boolean condition can never be true

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

Random myNumber = new Random();

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

Relational

>, <, and == are ___________

Relational operators

Which of the following will format 12.7801 to display as $12.78?

System.out.printf("$%,.2f", 12.7801);

Which of the following will format 12.78 to display as 12.8%?

System.out.printf("%.1f%%", 12.78);

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

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

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

TRUE

A local variable's scope always ends at the closing brace of the block of code in which it is declared.

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 variable's scope is the part of the program that has access to that variable.

TRUE

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

TRUE

Application software refers to programs that make the computer useful to the user.

TRUE

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

TRUE

Encapsulation refers to the combining of data and code into a single object.

TRUE

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

TRUE

If the expression on the left side of the && operator is false, the expression on the right side will not be checked.

TRUE

In a switch statement, each of the case values must be unique.

TRUE

Java provides a set of simple unary operators designed just for incrementing and decrementing variables.

TRUE

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

TRUE

Named constants are initialized with a value and that value cannot change during the execution of the program.

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 Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.

TRUE

The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.

TRUE

The System.out.printf method allows you to format output in a variety of ways.

TRUE

The System.out.printf method formats a string and displays it in the console window.

TRUE

The computer is a tool used by so many professionals that it cannot be easily categorized.

TRUE

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

TRUE

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

TRUE

The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.

TRUE

The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.

TRUE

Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.

TRUE

When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption.

TRUE

When the continue 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.

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 you open a file with the PrintWriter class, the class can potentially throw an IOException.

TRUE

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

Without programmers, the users of computers would have no software, and, without software, computers would not be able to do anything.

TRUE

T

The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.

The boolean data type may contain which of the following range of values?

true or false

The boolean expression in an if statement must evaluate to

true or false

The __________ loop allows the user to decide on the number of iterations.

user controlled loop

The primitive data types only allow a(n) __________ to hold a single value.

variable

In Java, __________ must be declared before they can be used.

variables

What would be displayed as a result of executing the following code? int x = 15, y = 20, z = 32; x += 12; y /= 6; z -= 14; System.out.println("x = " + x + ", y = " + y + ", z = " + z);

x = 27, y = 3, z = 18

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

predict the Result What would each display on the screen if they were actual programs? The variable a starts with the value 10. The variable b starts with the value 2. The variable c starts with the value 4. Store the value of a times b in a. Store the value of b times c in c. Add a and c, and store the result in b. Display the value in b on the screen.

answer: 28

predict the Result What would each display on the screen if they were actual programs? The variable x starts with the value 0. The variable y starts with the value 5. Add 1 to x. Add 1 to y. Add x and y, and store the result in y. Display the value in y on the screen.

answer: 7

Because Java byte code is the same on all computers, compiled Java programs

are highly portable

How does that character 'A' compare the the character 'B'? a. 'A' is greater than 'B' b. 'A' is less than 'B' c. 'A' is equal to 'B' d. you cannot compare characters

b. 'A' is less than 'B'

These characters mark the beginning of a multi-line comment a. // b./* c.*/ d./**

b. /*

What will the println statement in the following program segment display? int x = 5; System.out.println(++x); a. 5 b. 6 c. 0 d. none of these

b. 6

which of thee following are not valid assignment statements? (indicate all that apply); a. total = 9; b. 72 = amount; c. profit = 129 d. letter = 'w';

b. 72 = amount; c. profit = 129

if you were to look at a machine language program, you would see_________: a. java source code b. a stream of binary numbers c. english words d. circuits

b. a stream of binary numbers

this type of program is designed to be transmitted over the internet and run in a web browser: a. application b. applet c. machine language d. source code

b. applet

the java compiler generates _______: a. machine code b. byte code c. source code d. HTML

b. byte code

When a program is finished using a file, it should do this. a. erase the file b. close the file c. throw an exception d. reset and read position

b. close the file

This section of a switch statement is branched to if none of of the case expressions match the switch expression. a. else b. default c. case d. otherwise

b. default

this type of loop always executes at least once. a. while b. do-while c. for d. any of these

b. do-while

The following data 72 'A' "Hello World" 2.8712 are all examples of __________; a. variables b. literals c. strings d. none of these

b. literals

Which Scanner class method would you use to read a string as an input? a. nextString b. nextLine c. readString d. getLine

b. nextLine

the do-while loop is this type of loop a. pretest b. posttest c. prefix d. postfix

b. posttest

these are words or names that are used to identify storage locations in memory and parts of the program that are created by the programmer: a. punctuation b. programmer-defined names c. key words d. operators

b. programmer-defined names

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

true or false. the = operator and the == operator perform the same operation

false

true or false. it is not necessary to initialize accumulator variables.

false

true or false. one limitation of the for loop is that only one variable may be initialized in the initialization expression

false

true or false. the do-while loops is a pretest loop

false

true or false. the for loop is a posttest loop

false

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

true or false. to calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.

false

true or false. when an if statement is nested in the else clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

false

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

flag

Which of the following is valid?

float w; w = 1.0f;

The __________ loop is ideal in situations where the exact number of iterations is known.

for

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

Each repetition of a loop is known as a(n) __________.

iteration

The switch statement is a

multiple alternative decision structure

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

myNumber = randomNumbers.nextInt(10) + 1;

Select all that apply. Which method of the Random class will return a random number within the range of 0.0 and 1.0?

nextDouble() nextFloat()

Which Scanner class method reads a String?

nextLine

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

single quotes, double quotes

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

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)

Which of the following is not a primitive data type?

string

When the + operator is used with strings, it is known as the

string concatenation operator

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

A program is a sequence of instructions stored in

the computer's memory

The central processing unit (CPU) consists of two parts which are

the control unit and the arithmetic and logic unit (ALU)

Internally, the central processing unit (CPU) consists of two parts which are __________

the control unit and the arithmetic/logic unit (ALU)

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

A __________ loop will always be executed at least once.

posttest

The two primary methods of programming in use today are

procedural and object-oriented

While __________ is centered on creating procedures, __________ is centered on creating objects.

procedural programming, object-oriented programming

A set of programming language statements that perform a specific task is a(n)

procedure

Computers can do many different jobs because they are

programmable

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

programming language

Software refers to

programs

A cross between human language and a programming language is called

pseudocode

One type of design tool used by programmers when creating a model of a program is

pseudocode

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

sentinel

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

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

set the accumulator variable to an initial value, often zero

________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.

short-circuit evaluation

True or False: A left brace in a java program is always followed by a right brace later in the program.

true

True or False: A variable must be declared before it can be used

true

True or False: you cannot change the value of a variable whose declaration uses the final key word

true

true or false. a conditionally executed statement should be indented one level from the if clause

true

true or false. all lines in a conditionally excuted block should be indented one level.

true

true or false. a variable may be defined in the initialization expression of the for loop

true

true or false. in a nested loop, the inner loop goes through all of its iterations for every iteration of the outer loop.

true

true or false. the scope of a variable is limited to the block in which it is defined.

true

true or false. the while loop is a pretest loop

true

true or false. when an if statement is nested in the if clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

true

A flag may have the values

true or false

An expression tested by an if statement must evaluate to

true or false

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);

5.0

Which of the following is the not equal operator?

!=

A Java source file must be saved with the extension

.java

Predict the Output: int freeze = 32, boil = 212; freeze = 0; boil = 100; System.out.println(freeze + "\n"+ boil + "\n");

0 100

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;

0.0

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

0.0

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);

1 time

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

What would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 100000) if (dept == 'R') bonus = 2000; else bonus = 1500; else if (sales > 75000) if (dept == 'R') bonus = 1250; else bonus = 1000; else bonus = 0;

1000

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

110

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 does the following code display? double x = 12.3798146; System.out.printf("%.2f\n", x);

12.38

What will be the value of x after the following statements are executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }

20

What is the value of charges after the following code has been executed? double charges, rate = 7.00; int time = 180; charges = time <= 119 ? rate * 2 : time / 60.0 * rate;

21.00

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

210

Predict the Output: int a, x = 23; a = x % 2; System.out.println(x + "\n" + a);

23 1 Explanation: In this case, 23 divided by 2 has a remainder of 1, so a will be assigned the value 1.

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 values of x and y after the following code is executed? int x, y = 15, z = 3; x = (y--) / (++z);

3

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

40

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

What is the result of the following expression? 10 + 5 * 3 - 20

5

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100);

5 times

What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", ");

5, 8, 11, 14

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

a class definition

T

Application software refers to programs that make the computer useful to the user.

This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information: A. memory B. cpu C. secondary storage D. input device

B. cpu

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

Demo.class

T

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

T

Encapsulation refers to the combining of data and code into a single object.

The contents of a variable cannot be changed while the program is running.

F (can be changed)

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

Both character and string literals can be assigned to a char variable.

FALSE

Class names and key words are examples of variables.

FALSE

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

FALSE

Compiled byte code is also called source code.

FALSE

In a for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

FALSE

In a for loop, the control variable is always incremented.

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

Java is not case sensitive.

FALSE

Java source files end with the .class extension.

FALSE

Programs never need more than one path of execution.

FALSE

The contents of a variable cannot be changed while the program is running.

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

F (end with .java extension)

Java source files end with the .class extension.

&&, ||, and ! are ____________

Logical operators

What would be printed out as a result of the following code? System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen.");

Nothing - this is an error

What will be displayed as a result of executing the following code? public class test { public static void main(String[] args) { int value1 = 9; System.out.println(value1); int value2 = 45; System.out.println(value2); System.out.println(value3); value = 16; } }

Nothing. Code will not compile

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y)

Nothing. There is an error in the code.

_________ is an empty statement that does nothing

Null statement

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 || number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); }

Numbers in the range 100 - 500

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

Scanner keyboard = new Scanner(System.in);

Find the error The following pseudocode algorithm has an error. The program is supposed to ask the user for the length and width of a rectangular room, and then display the room's area. The program must multiply the width by the length in order to determine the area. Find the error. area = width * length Display "What is the room's width?" Input width Display "What is the room's length?" Input length Display area

The calculation for area is done before the values are entered

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10;

The code contains an error and will not compile.

T

The computer is a tool used by so many professions that it cannot be easily categorized.

If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator");

The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

What would be displayed as a result of executing the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

There are 5785 hens in the hen house.

Predict the Output: System.out.print("Be careful\n)"; System.out.print("This might/n be a trick "); System.out.println("question.");

This would give an error bc of line one \n)"; but if that is fixed to System.out.print("Be careful\n"); then it will say: Be careful This might/n be a trick question.

A variable's scope is the part of the program that has access to that variable

True

When you call one of the Scanner classes methods to read a primitive value-- such as nextInt or nextDoulbe-- and then call the nextLine method to read a string, an error will occur

True

T

When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption.

T

Without programmers, the users of computers would have no software, and without software, computers would not be able to do anything.

To display the output on the next line, you can use the println method or use the __________ escape sequence in the print method.

\n

Select all that apply. Which of the following steps is normally performed by a for loop?

a. update the control variable during each iteration b. test the control variable by comparing it to a maximum or minimum value c. terminate when the control variable reaches its maximum or minimum value d. initialize the control variable to a starting value

when determining whether a number is inside a range, it's best to use this operator. a. && b. ! c. || d. ? :

a. &&

What will the println statement in the following program segment display? int x = 5; system.out.println(x++); a. 5 b. 6 c. 0 d. none of these

a. 5

You can use this class to display dialog boxes a. JOptionPane b. BufferedReader c. InputStreamReader d. DialogBox

a. JOptionPane

to open a file for writing, you use the following class. a. PrintWriter b. FileOpen c. OutputFile d. FileReader

a. PrintWriter

which of the following are not valid println statements? (indicate all that apply): a. System.out.println + "Hello World"; b. System.out.println("Have a nice day"); c. out.System.println(value); d. println.out(Programming is great fun);

a. System.out.println + "Hello world"; c. out.System.println(value); d. println.out(programming is great fun);

each byte is assigned a unique: a. adress b.cpu c. bit d. variable

a. address

a group of statements, such as the contents of a class or a method, are enclosed in _________; a. braces {} b. parentheses () c. brackets [] d. any of these will do

a. braces {}

this type of operator lets you manually convert a value, even if it means that a narrowing conversion will take place. a. cast b. binary c. uploading d. dot

a. cast

this expression is executed by the for loop only once, regardless of the number of iterations. a. initialization expression b. test expression c. update expression d. pre-increment expression

a. initialization expression

this is a variable that controls the number of iterations performed by a loop. a. loop control variable b. accumulator c. iteration register variable d. repetition meter

a. loop control variable

which scanner class method would you use to read a double as input? a. nextDouble b. getDouble c. readDouble d. none of these; you can't

a. nextDouble

If you prematurely terminate an if statement with a semicolon, the compiler will

a. not display an error message b. assume you are placing a null statement there c. both (a) and (b)

the for loop is this type of loop a. pretest b. posttest c. prefix d. postfix

a. pretest

the while loop is this type of loop a. pretest b. posttest c. prefix d. postfix

a. pretest

these characters serve specific purposes, such as marking the beginning or ending of a statement, or separating items in a list: a. punctuation b. programmer-defined names c. key words d. operators

a. punctuation

this is a special value that signals when there are no more items from a list of items to be processed. this value cannot be mistaken as an item from the list. a. sentinel b. flag c. signal d. accumulator

a. sentinel

these are rules that must be follwoed while writing a program: a. syntax b. punctuation c. key words d. operators

a. syntax

an else clause always goes with ______. a. the closest previous if clause that doesn't already have its own else clause. b. the closest if clause c. the if clause that is randomly selected by the compiler d. none of these

a. the closest previous if clause that doesn't already have its own else clause.

the negation operator is _______; a. unary b. binary c. ternary d. none of these

a. unary

these characters mark the beginning of a single-line comment a. // b. /* c. */ d. /**

a.//

The variable used to keep a running total in a loop is called a(n) __________.

accumulator

Which of the following is a software entity that contains data and procedures?

an object

What is the value of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if ( x >= y) { ans = x + 10; x -=y; } else { ans = y + 10; y += x; }

ans = 35, x = 15, y = 40

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

__________ expression has a value of either true or false

boolean expression

A block of code is enclosed in a set of

braces, { }

This key word is used to declare a named constant. a. constant b. namedConstant c. final d. concrete

c. final

this type of loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless

c. infinite

these are words that have a special meaning in the programming language: a. punctuation b. programmer-defined names c. key words. d. operators

c. key words

in the expression number++, the ++ operator is in what mode? a. prefix b. pretest c. postfix d. posttest

c. postfix

the type of memory that can hold data for long periods of time - even when there is no power to the computer: a. RAM b. primary storage c. secondary storage d. CPU storage

c. secondary storage

Every complete statement ends with a _______: a. period b. parenthesis c. semicolon d. ending brace

c. semicolon

this determines whether two different string objects contain the same string. a. the == operator b. the = operator c. the equals method d. the stringCompare method

c. the equals method

the conditional operator takes _________ operands. a. one b. two c. three d. four

c. three

this is a named storage location in the computer's memory: a. class b. key word c. variable d. operator

c. variable

When Java converts a lower-ranked value to a higher-ranked type, it is called a(n) __________; a. 4-bit conversion b. escalating conversion c. widening conversion d. narrowing conversion

c. widening conversion

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

chrA != 'A'

these characters mark the beginning of a documentation comment a. // b. /* c. */ d. /**

d. /**

to open a file for reading, you use the following classes. a. File and Writer b. File and Output c. File and Input d. File and Scanner

d. File and Scanner

This class allows you to read a line from a file. a. FileWriter b. Scanner c. InputFile d. FileReader

d. FileReader

this class allows you to use the print and println methods to write data to a file. a. File b. FileReader c. OutputFile d. PrintWriter

d. OutputFile

this is a variable htat keeps a running total a. sentinel b. sum c. total d. accumulator

d. accumulator

A byte is made up of eight: A. cpus b. addresses c. variables d. bits

d. bits

To create a block of statements, you enclose the statements in these. a. parentheses() b. square brackets [] c. angled brackets <> d. braces {}

d. braces {}

what is each repetition of a loop known as? a. cycle b. revoluetion c. orbit d. iteration

d. iteration

14. JVM stands for ________: a. java variable machine b. java variable method c. java virtual method d. java virtual machine

d. java virtual machine

these are symbols or words that perform operations on one or more operands: a. punctuation b. programmer-defined names c. key words d. operators

d. operators

Variables are classified according to their

data types

if statement is a _____.

decision structure

An item that separates other items is known as a

delimiter

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");

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;

Variables of the boolean data type are useful for

evaluating conditions that are either true or false

True or False: comments that begin with // can be processed by javadoc.

false

True or False: if one of an operator's operands is a double, and the other operand is an int, java will automatically convert the value of the double to an int.

false

True or False: variable names may begin with a number.

false

The __________ statement is used to create a decision structure which allows a program to have more than one path of execution.

if

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

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

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

import java.io.*;

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

infinite

To compile a program named First you would use which of the following commands?

javac First.java

Which of the following cannot be used as identifiers in Java?

key words

A value that is written into the code of a program is a(n) __________.

literal

Which is a control structure that causes a statement or group of statements to repeat?

loop

The variable that controls the number of times a loop iterates is known as a(n) __________.

loop control variable

Each different type of CPU has its own

machine language

Validating the results of a program is important to

make sure the program solves the original problem

A(n) __________ is a software entity that contains data and procedures.

object

Byte code instructions are

read and interpreted by the JVM

The end of a Java statement is indicated by a ________.

semicolon (;)

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

An object typically hides its data but allows outside code access to

the methods that operate on the data

object

the programs that make the computer useful to the user

What is syntax?

the rules that must be followed when writing a program

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()) { ... }

Which of the following are pre-test loops?

while, for

Key words are

words that have a special meaning in the programming language

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

x <= y

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

x = (float)y;

If x has been declared an int, which of the following statements is invalid?

x = 1,000;

What will be the values of x aand y after the following code is executed? int x = 12, y = 5; x += y--;

x = 17, y = 4

Find the error Rewrite the following code to fix all the syntax errors: */ What's wrong with this program? /* public MyProgram { public static void main(String[ ] args); } int a, b, c \\Three integers a = 3 b = 4 c = a + b System.out.println('The value of c is' + C); {

• The comment symbols in the first line are reversed. They should be /* and */. • The word class is missing in the second line. It should read public class MyProgram. • The main header should not be terminated with a semicolon. • The fifth line should have a left brace, not a right brace. • The first four lines inside the main method are missing their semicolons. • The comment in the first line inside the main method should begin with forward slashes (//), not backward slashes. • The last line inside the main method, a call to println, uses a string literal, but the literal is enclosed in single quotes. It should be enclosed in double quotes, like this: "The value of c is". • The last line inside the main method passes C to println, but it should pass c (lowercase). • The class is missing its closing brace. ANSWER: public class MyProgram { public static void main(String[ ] args){ int a, b, c; //Three integers a = 3; b = 4; c = a + b; System.out.println("The value of c is" + c); } }


Related study sets

ACC 301 - Chapter 4 - Multiple Choice

View Set

Accounting 410 Final: Chapter 19

View Set

UWorld Microbiology and Antimicrobials

View Set

Management of Patients with Oncologic Disorders

View Set

Wong Ch 16:Health Problems of School-Age Children and Adolescents

View Set